|
18 | 18 | from django.contrib.auth.models import User
|
19 | 19 | from django.core.exceptions import ValidationError
|
20 | 20 | from django.core.validators import validate_email
|
21 |
| -from django.http import HttpResponse, Http404, JsonResponse |
| 21 | +from django.http import HttpResponse, Http404, JsonResponse, HttpResponseBadRequest |
22 | 22 | from django.shortcuts import render, get_object_or_404
|
23 | 23 | from django.urls import reverse
|
24 | 24 | from django.utils.decorators import method_decorator
|
@@ -68,18 +68,23 @@ def top_level(request):
|
68 | 68 | }
|
69 | 69 |
|
70 | 70 | serializer = Serializer()
|
71 |
| - desired_format = determine_format(request, serializer) |
| 71 | + try: |
| 72 | + desired_format = determine_format(request, serializer) |
| 73 | + except BadRequest as err: |
| 74 | + return HttpResponseBadRequest(str(err)) |
72 | 75 |
|
73 | 76 | options = {}
|
74 | 77 |
|
75 | 78 | if 'text/javascript' in desired_format:
|
76 | 79 | callback = request.GET.get('callback', 'callback')
|
77 | 80 |
|
78 | 81 | if not is_valid_jsonp_callback_value(callback):
|
79 |
| - raise BadRequest('JSONP callback name is invalid.') |
| 82 | + return HttpResponseBadRequest("JSONP callback name is invalid") |
80 | 83 |
|
81 | 84 | options['callback'] = callback
|
82 | 85 |
|
| 86 | + # This might raise UnsupportedFormat, but that indicates a real server misconfiguration |
| 87 | + # so let it bubble up unhandled and trigger a 500 / email to admins. |
83 | 88 | serialized = serializer.serialize(available_resources, desired_format, options)
|
84 | 89 | return HttpResponse(content=serialized, content_type=build_content_type(desired_format))
|
85 | 90 |
|
|
0 commit comments