@@ -95,9 +95,20 @@ async def pipeline_route(request: Request) -> Response:
95
95
] and already_left (request ):
96
96
logger .info ("Discarding request as the caller already left" )
97
97
return Response (status_code = 204 )
98
-
99
98
payload = await request .body ()
99
+
100
100
task = os .environ ["TASK" ]
101
+
102
+ try :
103
+ inputs , params = normalize_payload (payload , task , sampling_rate = sampling_rate )
104
+ except EnvironmentError as e :
105
+ logger .error ("Error while parsing input %s" , e )
106
+ return JSONResponse ({"error" : str (e )}, status_code = 500 )
107
+ except Exception as e :
108
+ # We assume the payload is bad -> 400
109
+ logger .warning ("Error while parsing input %s" , e )
110
+ return JSONResponse ({"error" : str (e )}, status_code = 400 )
111
+
101
112
if os .getenv ("DEBUG" , "0" ) in {"1" , "true" }:
102
113
pipe = request .app .get_pipeline ()
103
114
try :
@@ -106,7 +117,6 @@ async def pipeline_route(request: Request) -> Response:
106
117
sampling_rate = pipe .sampling_rate
107
118
except Exception :
108
119
sampling_rate = None
109
- inputs , params = normalize_payload (payload , task , sampling_rate = sampling_rate )
110
120
except ValidationError as e :
111
121
errors = []
112
122
for error in e .errors ():
0 commit comments