Boavizta / boaviztapi

🛠 Giving access to BOAVIZTA reference data and methodologies trough a RESTful API
GNU Affero General Public License v3.0
66 stars 23 forks source link

Catch errors instead of returning CORS errors to users #240

Closed da-ekchajzer closed 7 months ago

da-ekchajzer commented 8 months ago

Problem

When the API raises an error (wich is not catch), FastAPI doesn't put the CORS header. This result on users having a CORS error even if the issue is related with the API process.

If you receive a 500 response that means you have an error in your backend app code (Python using FastAPI). It doesn't have anything to do with CORS. If you have an error, your app won't be able to send any headers used for CORS. But the problem is not at CORS, is before that.

https://github.com/tiangolo/fastapi/issues/775#issuecomment-585413335

Solution

We should provide a clearer message to users when the API raises an error.

Some workaround can be found here (https://github.com/tiangolo/fastapi/issues/775)

This issue could be the beginning of an error managing system

PierreRustOrange commented 7 months ago

Given the corresponding PR has been merged, we could probably close this.

BTW, I had another proposition to work around this issue, based on a exception_handler (adding explicitly the CORS header when we get an app level exception) , but I don't know enough of starlette to know if it's better or worse than the solution from @cosmastech .

da-ekchajzer commented 7 months ago

I am not familiar with it either. I am closing the issue. We could open an issue on the error managing system which might use exception_handler.