-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): return JSON response with Internal Server Error for any…
… exceptions Part of #48
- Loading branch information
Showing
3 changed files
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
from fastapi import FastAPI | ||
from fastapi import FastAPI, Request, status | ||
from fastapi.responses import JSONResponse | ||
from routes import router | ||
|
||
from custom_routes import router as custom_router | ||
|
||
app = FastAPI() | ||
|
||
@app.exception_handler(Exception) | ||
async def exception_handler(request: Request, ex: Exception): | ||
return JSONResponse( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
content={"error": "Internal Server Error"} | ||
) | ||
|
||
app.include_router(router) | ||
|
||
app.include_router(custom_router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters