FOSRestBundle
FOSRestBundle copied to clipboard
Log json_decode errors
If the @json_decode($data, true) from json decoders fail, we just have this error:
[2018-02-08 07:59:59] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\BadRequestHttpException: "Invalid json message received" at /vendor/friendsofsymfony/rest-bundle/EventListener/BodyListener.php line 115 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException(code: 0): Invalid json message received at /vendor/friendsofsymfony/rest-bundle/EventListener/BodyListener.php:115)"} []
It's hard to know what is the issue. We can't log the submitted data for sensitive reason but we don't even have the json_decode error.
We may log it with json_last_error_msg.
We might also use nette/utils with proper json excpetion management: https://doc.nette.org/en/2.4/json#toc-decode
FOSRest didn't work for POST requests with escaped json body. I had to my own decoder.