Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions mapped in config aren't caught anymore, 500 is thrown instead #2369

Open
SebastienTediber opened this issue May 23, 2022 · 5 comments

Comments

@SebastienTediber
Copy link

Hello,

Since we updated to 3.x.x, the exceptions I mapped in my config files aren't caught and a 500 is thrown instead.

Here is my configuration :

fos_rest:
    exception:
        enabled: true
        messages:
            Symfony\Component\HttpKernel\Exception\HttpException: true
            InvalidArgumentException: true
            Sylius\Component\Resource\Exception\UnexpectedTypeException: true
            PHPUnit\Framework\Warning: true

    view:
        formats:
            json: true
            xml:  true
        empty_content: 204
    format_listener:
        rules:
            - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true }
            - { path: '^/api/.*', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
            - { path: '^/cron/.*', priorities: ['json'], fallback_format: json, prefer_extension: false }
            - { path: '^/', stop: true }

I have been trying with InvalidArgumentException thrown.

I have been changing the configuration a few times, adding the code to my exception too, it still does not work.

@GuillaumeTediber
Copy link

Hello
@goetas @W0rma

Do you have any ideas in how to use fos_rest error caching functionnality for version 3.X.X ?
This would help us a lot.

Thank you,

Guillaume Bidan
CTO
Tediber

@WissameMekhilef
Copy link

Hi!

I have also been facing this issue, trying to clean up the log output to focus on what matter and having uncaught exception is making it harder.

@InjustFr
Copy link

InjustFr commented Jul 4, 2022

@SebastienTediber I think your configuration needs an update. Mine is working fine, here it is (the exception part):

fos_rest:
    exception:
        map_exception_codes: true
        codes:
            'InvalidArgumentException': 422
            'Doctrine\ORM\EntityNotFoundException': 404
        messages:
            'InvalidArgumentException': true
            'Doctrine\ORM\EntityNotFoundException': true

You also have to set exception_controller to null in twig.yaml, if you're using twig

@SebastienTediber
Copy link
Author

Hello @InjustFr,

We investigated the issue further and came upon a Twig issue too indeed, that we fixed differently. I will look into what you propose though because it looks better than our solution.

Thanks

@SebastienTediber
Copy link
Author

Hello again @InjustFr ,

We tried your solution and it works fine for us.

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants