You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from fastapi import FastAPI, Body, Response
from fastapi.responses import JSONResponse
import azure.functions as func
app = FastAPI()
@app.exception_handler(Exception)
async def catch_all(req, e:Exception):
return JSONResponse("Catch all handler")
# @app.exception_handler(ZeroDivisionError)
# async def zero_handler(req, e:ZeroDivisionError):
# return JSONResponse("Zero handler")
@app.post("/test")
async def test():
a = 20 / 0
return {
'content': "Hello"
}
main = func.AsgiMiddleware(app).main
If I remove the comments on the ZeroDivisionError handler, then running with func start cathes the divide by zero exception. However, with the code as is, when running with uvicorn, the Exception handler catches is, but running with func start, doesn't.
I use scripts/run-local.sh to run via uvicorn and scripts/run-local-az.sh to run with the azure function host.
Expected behavior
Provide a description of the expected behavior.
When running with func start, an Exception handler should catch all exceptions. The behaviour should be the same as when running with uvicorn.
Actual behavior
Provide a description of the actual behavior observed.
The behaviour differs from running with uvicorn. Only specific exceptions are caught.
Known workarounds
Provide a description of any known workarounds.
Other than writing a handler for every possible error, there doesn't seem to be one.
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
Investigative information
Please provide the following:
Repro steps
Provide the steps required to reproduce the problem:
I'm using the AsgiMiddleware to wrap a FastApi app. If I add an exception_handler for Exception, then specific errors like ZeroDivisionError are not caught when running with func start, however, it works if I use uvicorn to run the app instead of func start. Please see https://github.com/ashic/azfn-fastapi-demo/blob/main/src/azfn_fastapi_demo/main.py
The main function is here:
If I remove the comments on the ZeroDivisionError handler, then running with func start cathes the divide by zero exception. However, with the code as is, when running with uvicorn, the Exception handler catches is, but running with func start, doesn't.
I use scripts/run-local.sh to run via uvicorn and scripts/run-local-az.sh to run with the azure function host.
Expected behavior
Provide a description of the expected behavior.
When running with func start, an Exception handler should catch all exceptions. The behaviour should be the same as when running with uvicorn.
Actual behavior
Provide a description of the actual behavior observed.
The behaviour differs from running with uvicorn. Only specific exceptions are caught.
Known workarounds
Provide a description of any known workarounds.
Other than writing a handler for every possible error, there doesn't seem to be one.
Contents of the requirements.txt file:
Provide the requirements.txt file to help us find out module related issues.
azure-functions==1.17.0
fastapi==0.104.1
uvicorn==0.24.0.post1
The text was updated successfully, but these errors were encountered: