FastAPI · Error
RequestValidationError
FastAPI lets you replace default responses for HTTP errors and invalid request data. Custom handlers receive the request and exception, then return a response you choose.
Last updated
Syntax
@app.exception_handler(ExceptionType)
async def handler(request: Request, exc: ExceptionType):
return Response(...)In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
FastAPIHTTPExceptionRequestValidationErrorStarletteHTTPExceptionPlainTextResponseJSONResponsejsonable_encoderhttp_exception_handler