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

CORS Headers not added on Exception (500 error code) #62

Closed martinopic closed 1 year ago

martinopic commented 8 years ago

The bundle does not add CORS headers on error (500) response, e.g. those generetaed by FOSRestBundle

lbayerl commented 8 years ago

+1

mmeloni commented 8 years ago

+1

hugomn commented 8 years ago

I have a curious case here. I have a POST endpoint that returns a 404 status. When the request payload is empty, the CORS header is correctly added. When it has any content ({'foo': 'bar'} for example) it's not added. Anyone has seen this?

martinopic commented 8 years ago

I don't think CORS headers are not added to 500 response, we have an application that uses FOSRestBundle and we got CORS headers on 500 responses. The problem, I think, is with PHP fatal errors which are not exceptions e.g. memory exceeded but, unfortunately, also NPEs.

The only way I know of handling these errors is to register a custom function but as the script completely stop to execute when encountering a fatal error the function would be "outside symfony" and all error hadling, error rest response and cors headers should be done outside the framework inside this very single function. Not impossible but really annoying and clumsy.

Pretty much a PHP limit. Seems to be overcome in PHP version 7 (still haven't tried that): http://php.net/manual/en/language.errors.php7.php

Seldaek commented 8 years ago

Even in PHP7. not all errors are catchable unfortunately, although more are.

samdjstevens commented 6 years ago

I'm seeing this happen (no Access-Control-Allow-Origin header present) on routes that through a NotFoundHttpException or doctrine exceptions. Is this expected behaviour?

st0at commented 4 years ago

I got the same issue, I'm using Symfony 3.4 and Nelmio Cors 1.5.6. I think this is related to: https://github.com/nelmio/NelmioCorsBundle/issues/124 @Seldaek is this issue fixed in new Nelmio Cors version 2.0.1?

xDaizu commented 4 years ago

@st0at It is not, because I am finding this case on version 2.0.1. And it's not on a fatal error, just a regular exception thrown by the phpoffice/phpspreadsheet library:

throw new Reader\Exception('Unable to identify a reader for this file');
podorozhny commented 3 years ago

+1, annoying af

Seldaek commented 1 year ago

Closing as duplicate of https://github.com/nelmio/NelmioCorsBundle/issues/124