
def jsonapi_exception_handler(exc, context):
    """
    Custom exception handler that returns errors object as an array with a 'detail' member
    """
    from rest_framework.views import exception_handler
    response = exception_handler(exc, context)

    if response is not None:
        if 'detail' in response.data:
            response.data = {'errors': [response.data]}
        else:
            response.data = {'errors': [{'detail': response.data}]}

    # Returns 401 instead of 403 during unauthorized requests without having user to log in with Basic Auth
    if response is not None and response.data['errors'][0]['detail'] == "Authentication credentials were not provided.":
        response.status_code = 401

    return response

@@ -467,17 +467,16 @@
 # Return
-s
  401 ins
@@ -540,11 +540,8 @@
 ser 
-to 
 log 

Edit comment