2383_설계

convention


시스템끼리 convention 다를 경우


error 관리

app = FastAPI()

class CustomError(HTTPException):
    def __init__(self, status_code: int, detail: str = None):
        super().__init__(status_code=status_code, detail=detail)

@app.exception_handler(CustomError)
async def custom_error_handler(request: Request, exc: CustomError):
    return JSONResponse(
        status_code=exc.status_code,
        content={"message": exc.detail},
    )

@app.get("/raise-error")
async def raise_error():
    raise CustomError(status_code=400, detail="error message")

ERD