-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from guivaloz/guivaloz/externos-con-clave
Validation Exception Handler
- Loading branch information
Showing
5 changed files
with
76 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
FastAPI Validation Exception Handler | ||
""" | ||
|
||
from fastapi import Request, status | ||
from fastapi.encoders import jsonable_encoder | ||
from fastapi.exceptions import RequestValidationError | ||
from starlette.responses import JSONResponse | ||
|
||
|
||
def validation_exception_handler(request: Request, exc: RequestValidationError): | ||
"""Manejador de excepciones de validación""" | ||
payload = { | ||
"success": False, | ||
"message": "Error de validación", | ||
"errors": list(exc.errors()), | ||
"data": [], | ||
} | ||
return JSONResponse( | ||
content=jsonable_encoder(payload), | ||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters