rebuild(stage-1): establish isolated application skeleton
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
def install_error_handlers(application: FastAPI) -> None:
|
||||
@application.exception_handler(Exception)
|
||||
async def unexpected_error(_request: Request, _error: Exception) -> JSONResponse:
|
||||
correlation_id = uuid.uuid4().hex
|
||||
return JSONResponse(
|
||||
status_code=500,
|
||||
content={
|
||||
"error": {
|
||||
"code": "internal_error",
|
||||
"message": "服务暂时不可用,请稍后重试。",
|
||||
"correlation_id": correlation_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user