FastAPI · Decorator
@app.exception_handler
@app.exception_handler() registers a function that handles a chosen exception class or HTTP status code. The function receives the request and exception, then returns the response for the error.
Last updated
Syntax
app.exception_handler(exc_class_or_status_code)In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
FastAPIRequestJSONResponseHTTPExceptionRequestValidationErrorStarletteHTTPExceptionhttp_exception_handlerrequest_validation_exception_handler