Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise NotAcceptable if suffix or query format is not acceptable #9593

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rest_framework/negotiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Content negotiation deals with selecting an appropriate renderer given the
incoming request. Typically this will be based on the request's Accept header.
"""
from django.http import Http404

from rest_framework import exceptions
from rest_framework.settings import api_settings
Expand Down Expand Up @@ -85,7 +84,10 @@ def filter_renderers(self, renderers, format):
renderers = [renderer for renderer in renderers
if renderer.format == format]
if not renderers:
raise Http404
raise exceptions.NotAcceptable(
detail="Could not satisfy the request format suffix or query.",
available_renderers=renderers
)
return renderers

def get_accept_list(self, request):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_negotiation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from django.http import Http404
from django.test import TestCase

from rest_framework.exceptions import NotAcceptable
from rest_framework.negotiation import (
BaseContentNegotiation, DefaultContentNegotiation
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_raise_error_if_no_suitable_renderers_found(self):
class MockRenderer:
format = 'xml'
renderers = [MockRenderer()]
with pytest.raises(Http404):
with pytest.raises(NotAcceptable):
self.negotiator.filter_renderers(renderers, format='json')


Expand Down
Loading