I'm forced to set all values in a response_model as Optional.
class ConnectOut(BaseModel):
product_id: Optional[str]
expires_at: Optional[datetime]
detail: Optional[ErrorType]
If I don't do that the HTTP400 path below throws validation errors, because product_id and expires_at won't be provided in case of a 400 error.
@router_connect.post("/", status_code=200, response_model=ConnectOut)
async def connect(
body: ConnectIn,
response: Response,
):
if account.is_banned:
response.status_code = status.HTTP_400_BAD_REQUEST
return {"detail": ErrorType.USER_IS_BANNED}
Is there a way to define a response_model for success and response_model for 400 Error messages?
Many Thanks,