Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Missing "errors" field in error response #218

Closed
@joeyespo

Description

@joeyespo

The 400-level errors are responding with a JSON array containing error objects, but the JSON API spec requires a top-level error field.

To reproduce
  1. Use serializer.is_valid(raise_exception=True) in an API view

  2. Send invalid JSON from the client to any API endpoint

    Example:

    ajax({
      url: '/my/api',
      contentType: 'application/vnd.api+json',
      type: 'POST',
      data: 'not JSON'
    });

    Expected response:

    {
      "errors": [
        {
          "status": "400",
          "source": {"pointer": "/data"},
          "detail": "JSON parse error - No JSON object could be decoded"
        }
      ]
    }

    Actual response:

      [
        {
          "status": "400",
          "source": {"pointer": "/data"},
          "detail": "JSON parse error - No JSON object could be decoded"
        }
      ]

It seems like the exception handler is properly setting the resource name, which should be used here. The former gets called, but the latter does not. DRF seems to have taken over, responding with this project's exception_handler as-is.

My requirements
...
Django==1.9.1
djangorestframework==3.3.3
djangorestframework-jsonapi==2.0.0-beta.2
...
My config
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.BasicAuthentication',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_json_api.renderers.JSONRenderer',
    ),
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser',
    ),
    'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions