-
-
Notifications
You must be signed in to change notification settings - Fork 536
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
Django 3.1: CORS headers not set on error responses? #578
Comments
Hi! Yes we should probably do this. But does it help you if CORS headers are set on error responses? Was the error expected on the server side, and something you could then process in browser? *Thanks, |
In our case, yes, I think we definitely want CORS headers set on error responses. We're using graphene-django to build a GraphQL API. If the client sends us a malformed query, we want to be able to return a sensible error without the browser tripping over CORS restrictions. I can't say this is universal, but I would guess most people building APIs in Django and setting CORS headers would also want those headers on their error responses. Do you think it's correct to treat |
This comment has been minimized.
This comment has been minimized.
@bjmc Hello! did you go with that solution in the end? We are facing this same issue here with our graphene-django API endpoing. |
Hi @marcosalcazar yes, we just subclassed |
Cool, thanks @bjmc for the quick response! |
A "+ 1" for adding support for The suggested workaround doesn't seem to work for me – when raising As an fun fact, this can be raised (with the workaround in place) and will get the correct headers: class StrangeException(HttpResponse, Exception):
pass
...
raise StrangeException("Invalid response", status=400) |
It would help coworkers if the real error messages in the browser console were not hidden by CORS check errors 🙂 |
Hello, I'm not sure if there's something I'm misunderstanding, but from my experiments, it seems like
django-cors-headers
is not setting CORS headers on HTTP 4XX error responses, when used with Django 3.1. I know there's been some changes to the way middleware are handled over the years. Is it possible thatdjango-cors-headers
needs to be updated to be fully compatible with newer versions?As an experiment, I added a
process_exception()
method toCorsMiddleware
, like this:And that seems to have resolved my issue. Is this a sensible way to proceed? If so, I'm happy to put together a formal pull request.
Thanks for a useful library!
The text was updated successfully, but these errors were encountered: