I have a fastapi application hosted on google cloud run. When exceptions are thrown, google cloud logs and error reporting show multiple different errors in packages like uvicorn, anyio (EndOfStream), and starlette. These errors aren't very useful to me, because they aren't the actual error thrown from my code. These exceptions are often accompanied by messages such as:
During handling of the above exception, another exception occurred:
Is there a way to avoid those errors from being thrown or from showing in Google Cloud Error Reporting and just have the actual exception from my code thrown by itself instead?
I have tried adding custom exception handlers to fastapi, but it doesn't seem to resolve the issue.
Ok through a combination of using a custom exception handler for fastapi and this answer I was able to come up with the following solution: