request: Use Django 5.2 HttpRequest.get_preferred_type.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2025-06-10 10:48:35 -07:00
committed by Tim Abbott
parent 6006ba4c44
commit d24eab02d2
4 changed files with 10 additions and 57 deletions

View File

@@ -33,7 +33,7 @@ from zerver.lib.exceptions import ErrorCode, JsonableError, MissingAuthenticatio
from zerver.lib.markdown import get_markdown_requests, get_markdown_time
from zerver.lib.per_request_cache import flush_per_request_caches
from zerver.lib.rate_limiter import RateLimitResult
from zerver.lib.request import RequestNotes, get_preferred_type
from zerver.lib.request import RequestNotes
from zerver.lib.response import (
AsynchronousResponse,
json_response,
@@ -377,7 +377,7 @@ class LogRequests(MiddlewareMixin):
class JsonErrorHandler(MiddlewareMixin):
def process_exception(self, request: HttpRequest, exception: Exception) -> HttpResponse | None:
if isinstance(exception, MissingAuthenticationError):
if get_preferred_type(request, ["application/json", "text/html"]) == "text/html":
if request.get_preferred_type(["application/json", "text/html"]) == "text/html":
# If this looks like a request from a top-level page in a
# browser, send the user to the login page.
#