API Platform version(s) affected: 3.2.4
Description
We build a Hydra-based API that returns mostly json-ld.
Behaviour in 3.1
(Almost) every error response the API returned contained Hydra properties ('hydra:title', 'hydra:description') and used the content-type 'application/ld+json', regardless of the error source, wether it was an (expected) routing error, authentication error or validation problem.
Behaviour in 3.2
By setting rfc_7807_compliant_errors: true we expect the returned content-type and also the returned JSON structure to change.
But in a consistent way. Currently results are very inconsistent:
E.g. validation errors use 'application/problem+json; charset=utf-8' and return Hydra properties.
But calling an endpoint with an unsupported method, that result in a 405 with No route found for "DELETE http://localhost/documents": Method Not Allowed (Allow: GET, POST), the content-type is 'application/ld+json' with a JSON problem structure but without Hydra properties.
Same for 404s with No route found ..., while other 404s caused by invalid entity IDs etc have Hydra properties and the 'application/problem+json; charset=utf-8' content-type.
JSON content changes
Sometime (often together with the content-type) the value of the 'type' property changes.
E.g. 404 from route not found (no problem header, no hydra props) contains:
{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","status":404,"detail":"No route found for \u0022GET http:\/\/localhost\/providers\/abc\/challenges\u0022", [...]}
with 'type' referring to the RFC.
While other 404s, e.g. from entity not found contain:
{"@id":"\/errors\/404","@type":"hydra:Error","title":"An error occurred","detail":"Not Found","status":404,"type":"\/errors\/404","hydra:title":"An error occurred","hydra:description":"Not Found"}
with 'type' referring to /errors/404
This also happens for other status codes like 400, 403 etc.
How to reproduce
I have no reproducer but am sure that it could easily be reproduced with the demo app, by calling some nonexisting endpoints in the 3.1. and the 3.2 version and comparing the results.
with the online demo
Non-existent route (books with missing s):
curl -X 'GET' 'https://demo.api-platform.com/book/xx' -H 'accept: application/ld+json' -v
> content-type: application/ld+json
> {"@context":"\/contexts\/Error","@type":"hydra:Error","hydra:title":"An error occurred","hydra:description":"No route found for \u0022GET http:\/\/demo.api-platform.com\/book\/xx\u0022"}
-> no problem header, no JSON problem structure (no 'type', no 'detail')
existing endpoint but entity not found:
curl -X 'GET' 'https://demo.api-platform.com/book/xx' -H 'accept: application/ld+json' -v
> content-type: application/problem+json; charset=utf-8
>{"@id":"\/errors\/404","@type":"hydra:Error","title":"An error occurred","detail":"Invalid uri variables.","status":404,"type":"\/errors\/404","hydra:title":"An error occurred","hydra:description":"Invalid uri variables."}
-> with problem header, with problem + hydra structure
Possible Solution
I would expect an API to show consistent behaviour over all error responses (as it was with ApiPlatform <= 3.1), probably 3.2. needs to be extended to also enhance the Symfony base errors.
Additional Context
defaults:
extra_properties:
rfc_7807_compliant_errors: true
skip_deprecated_exception_normalizers: true
event_listeners_backward_compatibility_layer: false
keep_legacy_inflector: false
API Platform version(s) affected: 3.2.4
Description
We build a Hydra-based API that returns mostly json-ld.
Behaviour in 3.1
(Almost) every error response the API returned contained Hydra properties ('hydra:title', 'hydra:description') and used the content-type 'application/ld+json', regardless of the error source, wether it was an (expected) routing error, authentication error or validation problem.
Behaviour in 3.2
By setting
rfc_7807_compliant_errors: truewe expect the returned content-type and also the returned JSON structure to change.But in a consistent way. Currently results are very inconsistent:
E.g. validation errors use 'application/problem+json; charset=utf-8' and return Hydra properties.
But calling an endpoint with an unsupported method, that result in a 405 with
No route found for "DELETE http://localhost/documents": Method Not Allowed (Allow: GET, POST), the content-type is 'application/ld+json' with a JSON problem structure but without Hydra properties.Same for 404s with
No route found ..., while other 404s caused by invalid entity IDs etc have Hydra properties and the 'application/problem+json; charset=utf-8' content-type.JSON content changes
Sometime (often together with the content-type) the value of the 'type' property changes.
E.g. 404 from route not found (no problem header, no hydra props) contains:
{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","status":404,"detail":"No route found for \u0022GET http:\/\/localhost\/providers\/abc\/challenges\u0022", [...]}with 'type' referring to the RFC.
While other 404s, e.g. from entity not found contain:
{"@id":"\/errors\/404","@type":"hydra:Error","title":"An error occurred","detail":"Not Found","status":404,"type":"\/errors\/404","hydra:title":"An error occurred","hydra:description":"Not Found"}with 'type' referring to
/errors/404This also happens for other status codes like 400, 403 etc.
How to reproduce
I have no reproducer but am sure that it could easily be reproduced with the demo app, by calling some nonexisting endpoints in the 3.1. and the 3.2 version and comparing the results.
with the online demo
Non-existent route (books with missing s):
-> no problem header, no JSON problem structure (no 'type', no 'detail')
existing endpoint but entity not found:
-> with problem header, with problem + hydra structure
Possible Solution
I would expect an API to show consistent behaviour over all error responses (as it was with ApiPlatform <= 3.1), probably 3.2. needs to be extended to also enhance the Symfony base errors.
Additional Context