Closed ajay-sudosu closed 2 months ago
Suppose I have a model: class User(Basemodel): name: str age: str
And I have an endpoint something like: @app.post("/user", description="User add") def add_user(add_user_data: User): so_something()
I am expecting a request body with the user details as show above in pydantic model Question is how should I handle the case when request body is None
Note: I am using fastapi add_exception_handler() function to handle the incoming request before reaching it to the endpoint some thing like:
def handle_pydantic_validations(request: Request, exc: ValidationError): errors = exc.args[0] error_list = [{error["loc"][1]: error["msg"]} for error in errors] return make_response(status_code=status.HTTP_400_BAD_REQUEST, body={"body": error_list, "status_code": status.HTTP_400_BAD_REQUEST})
Privileged issue
Issue Content
Suppose I have a model: class User(Basemodel): name: str age: str
And I have an endpoint something like: @app.post("/user", description="User add") def add_user(add_user_data: User): so_something()
I am expecting a request body with the user details as show above in pydantic model Question is how should I handle the case when request body is None
Note: I am using fastapi add_exception_handler() function to handle the incoming request before reaching it to the endpoint some thing like:
def handle_pydantic_validations(request: Request, exc: ValidationError): errors = exc.args[0] error_list = [{error["loc"][1]: error["msg"]} for error in errors] return make_response(status_code=status.HTTP_400_BAD_REQUEST, body={"body": error_list, "status_code": status.HTTP_400_BAD_REQUEST})