Boavizta / boaviztapi

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

Uncaught exception to include CORS middleware #243

Closed cosmastech closed 7 months ago

cosmastech commented 7 months ago

To resolve https://github.com/Boavizta/boaviztapi/issues/240

da-ekchajzer commented 7 months ago

Thank you very much for your PR. Would it be possible to log the stack trace when error is catch ?

cosmastech commented 7 months ago

Thank you very much for your PR. Would it be possible to log the stack trace when error is catch ?

@da-ekchajzer Do we need to include any kind of logging set up or is this sufficient?

da-ekchajzer commented 7 months ago

@da-ekchajzer Do we need to include any kind of logging set up or is this sufficient?

Ok for me

Thanks for this update, we can consider #240 solved. I am not familiar with error handling in starlette, but the logger logs the following error before logging the excpeted error.

Traceback (most recent call last):
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/starlette/middleware/base.py", line 78, in call_next
    message = await recv_stream.receive()
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/anyio/streams/memory.py", line 98, in receive
    return self.receive_nowait()
  File "/home/da-ekchajzer/.cache/pypoetry/virtualenvs/boaviztapi-Sm2B5gn3-py3.10/lib/python3.10/site-packages/anyio/streams/memory.py", line 91, in receive_nowait
    raise EndOfStream
anyio.EndOfStream
During handling of the above exception, another exception occurred:

[The expected error]

I don't think it's an important problem, but just checking if you have any idea on the reason of this error.

cosmastech commented 7 months ago

I noticed the same thing. I'm quite new to Python, but I think this is an issue with how Starlette is handling the errors in anyio.memory.MemoryObjectReceiveStream. What I've done is remove this context from the traceback if the context of the Exception is anyio.EndOfStream.

da-ekchajzer commented 7 months ago

Great, thank you very much for your contribution.