from fastapi import FastAPI
from fastapi.exceptions import RequestValidationError
from .http_error import httpExceptionHandler
from .validation_error import validationExceptionHandler
from .app_error import appExceptionHandler
from starlette.exceptions import HTTPException as StarletteHTTPException

def registerCustomErrorHandle(server: FastAPI):
    """ 统一注册自定义错误处理器"""
    # 注册参数验证错误,并覆盖模式RequestValidationError
    server.add_exception_handler(RequestValidationError, validationExceptionHandler)
    server.add_exception_handler(StarletteHTTPException, httpExceptionHandler)    
    server.add_exception_handler(Exception, appExceptionHandler)