-
-
Notifications
You must be signed in to change notification settings - Fork 900
fix: errors bc with rfc_7807_compliant_errors false #5974
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
j-schumann
added a commit
to j-schumann/symfony-addons
that referenced
this pull request
Nov 17, 2023
3745547
to
51773bd
Compare
9043b1c
to
305ccad
Compare
Failing guides is expected as it doesn't test the code from this branch but from main, my local tests work :) |
Thank you for the clarification! |
1 task
@soyuka Hello, could you please help, what is the right way to create a ValidationException error from code now ?
|
BacLuc
added a commit
to BacLuc/ecamp3
that referenced
this pull request
Mar 22, 2025
It was a little tricky, but finally i figured out how to do it: https://api-platform.com/docs/core/errors/ The big impact is, that the serialization of the errors is now done with the same infrastructure as serializing entities. That makes it less format dependent. It seems a little weird that we use a provider to "replace" the exception path of the response by extracting the exception to the context, and then continuing like when we would serialize a response. But i can also see the benefits. See api-platform/core#5974 Issue: ecamp#6618
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this fix:
Try this:
composer.json:
TODO:
guide
Documentation:
Errors
Backward compatibility with < 3.1
Use the following configuration:
This can also be configured on an
ApiResource
or in anHttpOperation
, for example:Control your exceptions
With
rfc_7807_compliant_errors
a few things happen. First Hydra exception are compatible with the JSON Problem specification. Default exception that are handled by API Platform in JSON will be returned asapplication/problem+json
.To customize the API Platform response, replace the
api_platform.state.error_provider
with your own provider:Note that our validation exception have their own error provider at:
Domain exceptions
Another way of having full control over domain exceptions is to create your own Error resource:
We recommend using the
\ApiPlatform\Metadata\Exception\ProblemExceptionInterface
and the\ApiPlatform\Metadata\Exception\HttpExceptionInterface
. For security reasons we add:normalizationContext: ['ignored_attributes' => ['trace', 'file', 'line', 'code', 'message', 'traceAsString']]
because you usually don't want these. You can override this context value if you want.Exception status code:
exception_to_status
and take one if there's a matchSymfony\Component\HttpKernel\Exception\HttpExceptionInterface
we get its status.ApiPlatform\Metadata\Exception\ProblemExceptionInterface
and there is a status we use itApiPlatform\Metadata\Exception\HttpExceptionInterface
Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface
=> 400ApiPlatform\Validator\Exception\ValidationException
=> 422ErrorResource