Catch SQLAlchemyError exception.

pull/1906/head
grossmj 3 years ago
parent d759564e20
commit fffbb08a8e

@ -25,6 +25,7 @@ from fastapi import FastAPI, Request
from starlette.exceptions import HTTPException as StarletteHTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from sqlalchemy.exc import SQLAlchemyError
from uvicorn.main import Server as UvicornServer
from gns3server.controller.controller_error import (
@ -160,6 +161,15 @@ async def http_exception_handler(request: Request, exc: StarletteHTTPException):
)
@app.exception_handler(SQLAlchemyError)
async def sqlalchemry_error_handler(request: Request, exc: SQLAlchemyError):
log.error(f"Controller database error: {exc}")
return JSONResponse(
status_code=500,
content={"message": "Database error detected, please check logs to find details"},
)
@app.middleware("http")
async def add_extra_headers(request: Request, call_next):
start_time = time.time()

Loading…
Cancel
Save