Skip to content
Discussion options

You must be logged in to vote

fastapi allows you to override request validation exceptions. One sort of solution to this is to override the exception with a modified version of the default fastapi request validation exception handler and exclude the input/url field from the response i.e. :

@app.exception_handler(RequestValidationError)
async def request_validation_exception_handler(
    request: Request, exc: RequestValidationError
) -> JSONResponse:
    print(exc.errors())
    return JSONResponse(
        status_code=HTTP_422_UNPROCESSABLE_ENTITY,
        content={"detail": jsonable_encoder(exc.errors(), exclude={"input"})})

The downside of this method would be that this removes the input/url field from all exception…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@a-was
Comment options

@styper
Comment options

@kinuax
Comment options

Answer selected by Kludex
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
5 participants