Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

FOS Rest bundle - Not able to use customized error controller

$
0
0

I have a project with Symfony 4.4 and FosRestBundle. I'm trying to customize the exception handling by changing the json output. In this particular case I have a controller that receives a query string language param and it validates it's correct (en_GB, it_IT, etc...). So when I pass an incorrect language code I want it to be handled by my own controller. The exception is thrown but is catched by it never goes to my custom controller, seems like its directly Symfony who does the output. My fos_rest.yaml:

fos_rest:
  param_fetcher_listener: force
  exception:
    enabled: true
    exception_controller: 'AppBundle\Action\ExceptionAction'

My action controller:

    /**
     * @Route(
     *     "/api/v1/categories/{id}",
     *     name="get_category",
     *     methods={"GET"},
     *     requirements={"id"="\d+"}
     * )
     *
     * @QueryParam(
     *     name="language",
     *     requirements=@Assert\LanguageCode,
     *     strict=false,
     *     description="Language code in ISO format, i.e. fr_FR"
     * )
     *
     * @param Request $request
     *
     * @return JsonResponse
     */
    public function __invoke(Request $request): JsonResponse
    {
        /**
     * @Route(
     *     "/api/v1/categories/{id}",
     *     name="get_category",
     *     methods={"GET"},
     *     requirements={"id"="\d+"}
     * )
     *
     * @QueryParam(
     *     name="language",
     *     requirements=@Assert\LanguageCode,
     *     strict=false,
     *     description="Language code in ISO format, i.e. fr_FR"
     * )
     *
     * @param Request $request
     *
     * @return JsonResponse
     */
    public function __invoke(Request $request): JsonResponse
    {

One thing that bothers me is I can write whatever I want in the exception_controller configuration option (like non-existent-controller) and the code doesn't fail witch makes me think that something is not plugged correctly. Any ideas why this is not working? Thanks a lot!


Viewing all articles
Browse latest Browse all 3924


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>