Open vincentjdc opened 4 years ago
Can you check if https://github.com/FriendsOfSymfony/FOSRestBundle/issues/2200#issuecomment-629150462 works for you too?
Hi @xabbuh ,
I read that issue before posting mine (always searching before posting ;-)). Sadly, it doesn't change anything :-s
Please also note that :
twig:
# ...
exception_controller: null
framework:
# ...
error_controller: null
Is there a special reason for setting framework.error_controller
to null
?
Is there a special reason for setting
framework.error_controller
tonull
?
Probably but sincerely I can't remember why I set it to null
. It was when I upgraded the project to Symfony 4.4 and got a lot of deprecation warnings (in relation with exception management).
I just removed that setting and the behavior is different :
Doctrine\ORM\EntityNotFoundException
leads to a 500 error (in JSON)Note that I have fos_rest.execption.codes.Doctrine\ORM\EntityNotFoundException
set to 404
. I assume that error handling is done only by Symfony and so that conf is not used anymore ?
denyAccessUnlessGranted
in Controller leads to the 403 error (debug page), so not in JSON.For the first point, I can replace all EntityNotFoundException
by throwingSymfony\Component\HttpKernel\Exception\NotFoundHttpException
. It will "solve" the problem.
For the second, it is blocking as result in not JSON.
Am I missing something else ?
@vincentjdc Did you manage to resolve the issues that you had?
@vincentjdc I am also curious if you fixed since I am probably having same issue now.
Hi! I also have trouble with exceptions, could you please share solutions? Environment:
Symfony
: 4.4.18friendsofsymfony/rest-bundle
: 2.8.5jms/serializer-bundle
: 3.5.0Steps and configurations:
FOSRestBundle
from 2.7 to 2.8fos_rest.yaml
file as shown below
fos_rest:
body_listener: true
view:
view_response_listener: true
failed_validation: 422
empty_content: 204
formats:
rss: false
xml: false
json: true
serializer:
serialize_null: true
exception:
enabled: true
exception_listener: false
serializer_error_renderer: true
serialize_exceptions: false
map_exception_codes: true
messages:
'Symfony\Component\HttpKernel\Exception\HttpException': true
body_converter:
enabled: true
#access_denied_listener:
# json: true
format_listener:
rules:
- { path: '^/api', priorities: ['json'], fallback_format: json, prefer_extension: true }
- { path: '^/', priorities: [ 'html', '*/*'], fallback_format: html, prefer_extension: true }
routing_loader:
enabled: false
configuration before changes:
exception:
enabled: true
messages:
'Symfony\Component\HttpKernel\Exception\HttpException': true
routing_loader:
enabled: true
access_denied_listener:
json: true
Now, when app thrown an exception(for example Symfony\Component\HttpKernel\Exception\NotFoundHttpException
), I get a response in HTML format instead of JSON
Should I implement my custom hander for exceptions via event listener or something else or add some additional configurations? Thanks!
I'm working on a project with symfony 4.4 and FosRestBundle 2.7 and JMSSerializerBundle.
I just upgrade FOSRestBundle from 2.7 to 2.8.0-beta3.
I run some functional tests, all tests pass but got lot of deprecation warnings :
So i changed some config :
The only remaining is the one about the classify method (first one) but now the exceptions are not handled and the response is not more a JSON result like :
Since that change, all my functional tests with an exception are failing.
Any idea ?
Thank you