Symfony 4 different error render JSON for api call, TWIG for conventionnal HTTP

I have built a web app with symfony 4, I use web interface to manage some element on it, and have a REST Api on it to handle some small things via a mobile app.
My question is : how to render JSON error for my mobile app calls (call via an url contain /api/) ? And render twig error template for the others request ?

My Symfony app use "fos_rest", this is my config for my app, it work for return my json error message correctly, but when I have error on my web app, it show me my error in JSON format :

    body_listener: true

    param_fetcher_listener:  true
        view_response_listener:  true
        enabled: true
        enabled: true
            - { path: '^/api', priorities: [json, html], prefer_extension: true, fallback_format: json }
            - { path: '^/', stop: true }

thanks for your help

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *