@@ -320,7 +320,7 @@ def __init__(
320
320
openapi_extensions : dict [str , Any ] | None = None ,
321
321
deprecated : bool = False ,
322
322
middlewares : list [Callable [..., Response ]] | None = None ,
323
- custom_response_validation_http_code : int | HTTPStatus | None = None ,
323
+ custom_response_validation_http_code : HTTPStatus | None = None ,
324
324
):
325
325
"""
326
326
Internally used Route Configuration
@@ -399,7 +399,7 @@ def __init__(
399
399
# _body_field is used to cache the dependant model for the body field
400
400
self ._body_field : ModelField | None = None
401
401
402
- self .custom_response_validation_http_code : int | HTTPStatus | None = custom_response_validation_http_code
402
+ self .custom_response_validation_http_code : HTTPStatus | None = custom_response_validation_http_code
403
403
404
404
def __call__ (
405
405
self ,
@@ -2127,6 +2127,29 @@ def swagger_handler():
2127
2127
body = body ,
2128
2128
)
2129
2129
2130
+ def _validate_route_response_validation_error_http_code (
2131
+ self ,
2132
+ custom_response_validation_http_code : int | HTTPStatus | None ,
2133
+ ) -> HTTPStatus | None :
2134
+ if custom_response_validation_http_code and not self ._enable_validation :
2135
+ msg = (
2136
+ "'custom_response_validation_http_code' cannot be set for route when enable_validation is False "
2137
+ "on resolver."
2138
+ )
2139
+ raise ValueError (msg )
2140
+
2141
+ if (
2142
+ not isinstance (custom_response_validation_http_code , HTTPStatus )
2143
+ and custom_response_validation_http_code is not None
2144
+ ):
2145
+ try :
2146
+ custom_response_validation_http_code = HTTPStatus (custom_response_validation_http_code )
2147
+ except ValueError :
2148
+ msg = f"'{ custom_response_validation_http_code } ' must be an integer representing an HTTP status code."
2149
+ raise ValueError (msg ) from None
2150
+
2151
+ return custom_response_validation_http_code
2152
+
2130
2153
def route (
2131
2154
self ,
2132
2155
rule : str ,
0 commit comments