Skip to content

Commit

Permalink
Fix status code: split pipeline load from input parsing
Browse files Browse the repository at this point in the history
pipeline loading -> 500
input parsing -> 400

Signed-off-by: Raphael Glon <oOraph@users.noreply.github.com>
  • Loading branch information
oOraph committed Oct 7, 2024
1 parent 45907cd commit b16af65
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api_inference_community/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,19 @@ async def pipeline_route(request: Request) -> Response:
] and already_left(request):
logger.info("Discarding request as the caller already left")
return Response(status_code=204)

payload = await request.body()

task = os.environ["TASK"]

if os.getenv("DEBUG", "0") in {"1", "true"}:
pipe = request.app.get_pipeline()

try:
pipe = request.app.get_pipeline()
try:
sampling_rate = pipe.sampling_rate
except Exception:
sampling_rate = None
inputs, params = normalize_payload(payload, task, sampling_rate=sampling_rate)
except ValidationError as e:
errors = []
for error in e.errors():
Expand All @@ -122,6 +123,16 @@ async def pipeline_route(request: Request) -> Response:
except Exception as e:
return JSONResponse({"error": str(e)}, status_code=500)

try:
inputs, params = normalize_payload(payload, task, sampling_rate=sampling_rate)
except EnvironmentError as e:
logger.error("Error while parsing input %s", e)
return JSONResponse({"error": str(e)}, status_code=500)
except Exception as e:
# We assume the payload is bad -> 400
logger.warning("Error while parsing input %s", e)
return JSONResponse({"error": str(e)}, status_code=400)

accept = request.headers.get("accept", "")
lora_adapter = request.headers.get("lora")
if lora_adapter:
Expand Down

0 comments on commit b16af65

Please sign in to comment.