Every error comes out as {"errors": [...]} with status, title, detail, code and source (pointer, parameter or header), in the app language (Spanish and English included).
The package hooks into Laravel's exception handling and works the same on versions 10 to 13; if the app registers its own renderable, the app's wins. To throw one by hand:
throw JsonApiException::make(status: 404, pointer: '/data/relationships/author/data');
The title, detail and code are filled in from the status. A 5xx error hides its internals unless errors. (or app.debug) allows it.
Error codes
| Base code | Status | When |
|---|---|---|
request. | 406 | The Accept does not allow JSON:API (source.) |
request. | 415 | The Content-Type is not JSON:API (source.) |
request. | 400 | A malformed or not allowed query parameter (source.) |
request. | 400 | The body is not JSON or does not have the shape of a document (source.) |
request. | 400 | A malformed request that is neither a query nor a document problem |
request. | 403 | A POST with a client id and allow_ off |
auth. | 401 | Not authenticated; it never redirects to login |
auth. | 403 | No permission |
auth. | 403 | The signed URL is invalid or expired |
resource. | 404 | The resource does not exist (it does not reveal the model name) |
route. | 404 | The route does not exist |
request. | 405 | The method is not on the route; it carries Allow |
resource. | 409 | The type or id of the document are not those of the endpoint |
request. | 413 | The request body exceeds the limit |
request. | 419 | The CSRF or session token expired |
validation.<rule> / validation. | 422 | A validation rule failed (validation., validation.…); validation. when there is no rule name |
request. | 429 | Rate limit; it carries Retry-After |
server. / server. | 500 / 503 | Unexpected error or service unavailable |
Any other HTTP status uses http.<status> (for example http.402). Codes carry the prefix mundoprogra.json-api. (for example mundoprogra.json-api.validation.required). Change it with errors., replace codes one by one with errors., or turn them off with errors..
The order of the checks
When a request fails for more than one reason, only the first comes out, in this order:
Content-Type(415) and thenAccept(406).- The syntax of the query (
400). - The document: broken or malformed JSON (
400) or a clientid(403). - The route: method not allowed (
405) or a route that does not exist (404). - Authentication (
401). - The
FormRequest: a differenttypeorid(409) and then the rules (422). - Your controller: the query whitelist (
400) and a resource that does not exist (404).
Steps 1 to 3 run before auth: without a session, broken JSON is a 400, not a 401.