Closed jayrbolton closed 4 years ago
Sorry, for late reply. I saw this issue come through, but forgot to look into it. This definitely should already work. This is a normal use-case for sanic-cors and there are tests in place to ensure this functionality is working.
I will have to look more deeply into this to see if I can find a way of reproducing it.
No worries. I'll try to make a repo that reproduces this
I'm experiencing this issue as well. please fix
@idanbensha As mentioned above, this feature is already enabled and working in Sanic-CORS. If you can point me to some code that reproduces the error, I can fix the bug.
Figured that it was because the exception handler was an async method (as shown by sanic documentation). Once I removed the async keyword of my exception handler, it worked.
I'm investigating this problem further. Yes, I think sanic can use async exception handlers (as shown in the documentation), but for some reason when combined with sanic-cors it cannot. It's definitely a problem I want to solve, because there have been three issues and one PR opened in the last month with users experiencing the same problem.
I'd like responses to be CORS enabled for exceptions, but if the request is handled with an exception callback (using
@app.exception(ErrorClass)
), then CORS doesn't work.The log says:
[DEBUG] CORS: CORS was handled in the exception handler, skipping
Seems related to the
SANIC_CORS_SKIP_RESPONSE_MIDDLEWARE
and also https://github.com/ashleysommer/sanic-cors/issues/18Am I missing something in the docs?
Example exception handler that disables cors: