You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having a lot of trouble upgrading from 2.8.3 to 3.1 with regard to the custom exception codes and showing error messages.
After I upgraded, our endpoint error responses don't reflect the fos_rest.yml exception configuration. When they should return, for example, a 409 error because we threw a domain exception which should be mapped to 409, they instead return
{
"code": 500,
"message": "Internal Server Error"
}
this happens despite the fact that the actual HTTP status code of the response is 409. So the ResponseCodeStatus listener is clearly working, the serialization however is not. To my knowledge, after digging through logs and stack traces, there are no issues happening causing the serializer to fail.
I see that in the upgrade to major version 3, the FOS\RestBundle\Controller\TwigExceptionController was removed -- and when I look at the code for it, I see it was clearly equipped to do this custom exception mapping and render the JSON that I expect. Now the exception controller being used by the Symfony ExceptionListener is the Symfony\Bundle\TwigBundle\Controller\ExceptionController.
This Twigbundle exception controller doesn't seem to be equipped to serialize the JSON error as it doesn't contain any code relevant for reading the exception code mapping from FOSRestBundle and injecting this into the template it uses.
We also use JMS serializer with FOS/rest. If this TwigBundle ExceptionController is not the right controller, which one should we be using in order to properly serialize JSON errors in REST endpoints?
Update: setting the error_controller in twig.yaml to null fixed this for me. It now appears to be using the newer Symfony ErrorListener and Error Controller, which properly serialize the data. Would be great to hear confirmation that this is the correct way to fix the problem.
Hi all,
I am having a lot of trouble upgrading from 2.8.3 to 3.1 with regard to the custom exception codes and showing error messages.
After I upgraded, our endpoint error responses don't reflect the fos_rest.yml exception configuration. When they should return, for example, a 409 error because we threw a domain exception which should be mapped to 409, they instead return
this happens despite the fact that the actual HTTP status code of the response is 409. So the ResponseCodeStatus listener is clearly working, the serialization however is not. To my knowledge, after digging through logs and stack traces, there are no issues happening causing the serializer to fail.
I see that in the upgrade to major version 3, the FOS\RestBundle\Controller\TwigExceptionController was removed -- and when I look at the code for it, I see it was clearly equipped to do this custom exception mapping and render the JSON that I expect. Now the exception controller being used by the Symfony ExceptionListener is the Symfony\Bundle\TwigBundle\Controller\ExceptionController.
This Twigbundle exception controller doesn't seem to be equipped to serialize the JSON error as it doesn't contain any code relevant for reading the exception code mapping from FOSRestBundle and injecting this into the template it uses.
We also use JMS serializer with FOS/rest. If this TwigBundle ExceptionController is not the right controller, which one should we be using in order to properly serialize JSON errors in REST endpoints?
Below is some information about our versioning:
fos_rest.yaml configuration:
can anybody clarify for me what the proper configuration here is or if I'm missing something?
The text was updated successfully, but these errors were encountered: