Пример #1
0
def handler500(request, **kwargs):
    if getattr(request, 'is_api', False):
        # API exceptions happening in DRF code would be handled with by our
        # custom_exception_handler function in olympia.api.exceptions, but in
        # the rare case where the exception is caused by a middleware or django
        # itself, it might not, so we need to handle it here.
        return HttpResponse(json.dumps(base_500_data()),
                            content_type='application/json',
                            status=500)
    return render(request, 'amo/500.html', status=500)
Пример #2
0
def handler500(request, **kwargs):
    # To avoid database queries, the handler500() cannot evaluate the user - so
    # we need to avoid making log calls (our custom adapter would fetch the
    # user from the current thread) and set request.user to anonymous to avoid
    # its usage in context processors.
    request.user = AnonymousUser()
    if getattr(request, 'is_api', False):
        # API exceptions happening in DRF code would be handled with by our
        # custom_exception_handler function in olympia.api.exceptions, but in
        # the rare case where the exception is caused by a middleware or django
        # itself, it might not, so we need to handle it here.
        return HttpResponse(json.dumps(base_500_data()),
                            content_type='application/json',
                            status=500)
    return TemplateResponse(request, 'amo/500.html', status=500)