mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-13 17:40:54 +00:00
Catch SQLAlchemyError exception.
This commit is contained in:
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…
Reference in New Issue
Block a user