Skip to content

Json responses from exceptions and validation errors #1619

@NeoIsRecursive

Description

@NeoIsRecursive

Description

When a request wants json (Accept header === 'application/json' or something), request validation errors should be a 424 json-response with the errors as the body.

Also when an exception occurs in the "json" context, it would be preferable to not get the error view, but a json response with the exception.

new Response(
  body: [
      'message' => $failure->getMessage(),
      'code' => $failure->getCode(),
      'file' => $failure->getFile(),
      'line' => $failure->getLine(),
      'trace' => $failure->getTrace(),
]),

(a problem details response for all of these scenarios would be cool, but I guess that might be out-of-scope).

Right now you get a redirect or a view, which isn't that nice for api's.

Benefits

We can handle errors in apis better 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions