nelmio / NelmioCorsBundle

Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application
https://symfony.com/bundles/NelmioCorsBundle/
MIT License
1.89k stars 108 forks source link

onKernelResponse is not triggered in case of exception #124

Open olix21 opened 5 years ago

olix21 commented 5 years ago

Hello,

We are using NelmioCorsBundle in an API and if an exception is sent, Symfony does not trigger the kernel.response event but the kernel.exception one.

So the Access-Control-Allow-Origin is not set. It's a little bit annoying as if the http client send a wrong request, the request will blocked by the CORS instead of returning the reason.

Shouldn't we add $this->dispatcher->addListener('kernel.exception', array($this, 'onKernelResponse'), 0);?

Seldaek commented 5 years ago

Yes sounds like that might be correct, feel free to send a PR with a fix

Seldaek commented 1 year ago

I cannot reproduce this somehow, kernel.response still fires for me after kernel.exception is used to generate a response.. Can anyone still repro this?

mayesto commented 1 year ago

Hi @Seldaek, this is occurred when you throw some exception in event listener. When exception is thrown in controller everything is ok

Edit: For example event Symfony\Component\HttpKernel\Event\RequestEvent