27 lines
749 B
Python
27 lines
749 B
Python
![]() |
from fastapi import FastAPI
|
||
|
from fastapi.exceptions import RequestValidationError
|
||
|
from starlette.exceptions import HTTPException
|
||
|
|
||
|
from mooc.core.exceptions import (
|
||
|
validation_exception_handler,
|
||
|
http_exception_handler,
|
||
|
generic_exception_handler
|
||
|
)
|
||
|
|
||
|
# 应用的其他代码...
|
||
|
|
||
|
def create_app() -> FastAPI:
|
||
|
app = FastAPI(
|
||
|
title=settings.PROJECT_NAME,
|
||
|
version=settings.VERSION,
|
||
|
# 其他设置...
|
||
|
)
|
||
|
|
||
|
# 注册异常处理器
|
||
|
app.add_exception_handler(RequestValidationError, validation_exception_handler)
|
||
|
app.add_exception_handler(HTTPException, http_exception_handler)
|
||
|
app.add_exception_handler(Exception, generic_exception_handler)
|
||
|
|
||
|
# 应用的其他设置...
|
||
|
|
||
|
return app
|