@@ -62,50 +62,43 @@ def handler(self, app: EventHandlerInstance, next_middleware: NextMiddleware) ->
62
62
values : Dict [str , Any ] = {}
63
63
errors : List [Any ] = []
64
64
65
- try :
66
- # Process path values, which can be found on the route_args
67
- path_values , path_errors = _request_params_to_args (
68
- route .dependant .path_params ,
69
- app .context ["_route_args" ],
65
+ # Process path values, which can be found on the route_args
66
+ path_values , path_errors = _request_params_to_args (
67
+ route .dependant .path_params ,
68
+ app .context ["_route_args" ],
69
+ )
70
+
71
+ # Process query values
72
+ query_values , query_errors = _request_params_to_args (
73
+ route .dependant .query_params ,
74
+ app .current_event .query_string_parameters or {},
75
+ )
76
+
77
+ values .update (path_values )
78
+ values .update (query_values )
79
+ errors += path_errors + query_errors
80
+
81
+ # Process the request body, if it exists
82
+ if route .dependant .body_params :
83
+ (body_values , body_errors ) = _request_body_to_args (
84
+ required_params = route .dependant .body_params ,
85
+ received_body = self ._get_body (app ),
70
86
)
87
+ values .update (body_values )
88
+ errors .extend (body_errors )
71
89
72
- # Process query values
73
- query_values , query_errors = _request_params_to_args (
74
- route .dependant .query_params ,
75
- app .current_event .query_string_parameters or {},
76
- )
77
-
78
- values .update (path_values )
79
- values .update (query_values )
80
- errors += path_errors + query_errors
90
+ if errors :
91
+ # Raise the validation errors
92
+ raise RequestValidationError (_normalize_errors (errors ))
93
+ else :
94
+ # Re-write the route_args with the validated values, and call the next middleware
95
+ app .context ["_route_args" ] = values
81
96
82
- # Process the request body, if it exists
83
- if route .dependant .body_params :
84
- (body_values , body_errors ) = _request_body_to_args (
85
- required_params = route .dependant .body_params ,
86
- received_body = self ._get_body (app ),
87
- )
88
- values .update (body_values )
89
- errors .extend (body_errors )
97
+ # Call the handler by calling the next middleware
98
+ response = next_middleware (app )
90
99
91
- if errors :
92
- # Raise the validation errors
93
- raise RequestValidationError (_normalize_errors (errors ))
94
- else :
95
- # Re-write the route_args with the validated values, and call the next middleware
96
- app .context ["_route_args" ] = values
97
-
98
- # Call the handler by calling the next middleware
99
- response = next_middleware (app )
100
-
101
- # Process the response
102
- return self ._handle_response (route = route , response = response )
103
- except RequestValidationError as e :
104
- return Response (
105
- status_code = 422 ,
106
- content_type = "application/json" ,
107
- body = json .dumps ({"detail" : e .errors ()}),
108
- )
100
+ # Process the response
101
+ return self ._handle_response (route = route , response = response )
109
102
110
103
def _handle_response (self , * , route : Route , response : Response ):
111
104
# Process the response body if it exists
0 commit comments