Google Cloud Error Reporting showing extraneous errors

98 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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:

async def custom_exception_handler(exc: Exception):
    raise exc from None

app.add_exception_handler(Exception, handler=custom_exception_handler)