Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Unify the exception response format when converting to JSON #19333

Merged
merged 2 commits into from May 24, 2017
Merged

[5.5] Unify the exception response format when converting to JSON #19333

merged 2 commits into from May 24, 2017

Conversation

themsaid
Copy link
Member

Currently any normal Exception is converted to this JSON structure:

{"message": "..."}

In case debug mode is on, several other attributes appear (file, line, & trace).

However there are two exceptions to this structure, first a validation exceptions returns the following:

{
    "test": [
      "The test field is required."
    ]
  }

And an AuthenticationException returns:

{"error" : "Unauthenticated."}

In this PR I'm attempting to unify the error response by returning the following from a validation exceptions:

{
  "message": "The given data failed to pass validation.",
  "errors": {
    "test": [
      "The test field is required."
    ]
  }
}

If that PR is approved I'm going to change the response format in https://github.com/laravel/laravel/blob/develop/app/Exceptions/Handler.php#L55 as well, this will make it standard across the framework to have a message attribute in a JSON error response that consumers can use to render a message to the end user or log it somewhere for later.

@taylorotwell taylorotwell merged commit ab30713 into laravel:master May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants