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

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

Closed
martinopic opened this issue May 17, 2016 · 10 comments
Closed

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

martinopic opened this issue May 17, 2016 · 10 comments

Comments

@martinopic
Copy link

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

@lbayerl
Copy link

lbayerl commented Jul 7, 2016

+1

1 similar comment
@mmeloni
Copy link

mmeloni commented Aug 22, 2016

+1

@hugomn
Copy link

hugomn commented Aug 25, 2016

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
Copy link
Author

martinopic commented Aug 28, 2016

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
Copy link
Member

Seldaek commented Aug 29, 2016

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

@samdjstevens
Copy link

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
Copy link

st0at commented Feb 12, 2020

I got the same issue, I'm using Symfony 3.4 and Nelmio Cors 1.5.6. I think this is related to: #124
@Seldaek is this issue fixed in new Nelmio Cors version 2.0.1?

@xDaizu
Copy link

xDaizu commented Jul 23, 2020

@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
Copy link

+1, annoying af

@Seldaek
Copy link
Member

Seldaek commented Feb 15, 2023

Closing as duplicate of #124

@Seldaek Seldaek closed this as not planned Won't fix, can't repro, duplicate, stale Feb 15, 2023
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

9 participants