Skip to content

Commit

Permalink
Improve error handling in pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
eliteprox committed Jul 3, 2024
1 parent 61c475f commit 3e75dc4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion runner/app/routes/speech_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ async def speech_to_text(
audio.file.write(converted_bytes)
audio.file.seek(0)
logger.info("Converted m4a file to mp3")
except Exception as e:
return JSONResponse(
status_code=400,
content=http_error(f"Error processing audio file: {str(e)}"),
)

try:
return pipeline(
audio=audio.file.read(),
)
except Exception as e:
status_code = 500
if "Soundfile is either not in the correct format or is malformed" in str(e):
status_code = 400

return JSONResponse(
status_code=400,
status_code=status_code,
content=http_error(f"Error processing audio file: {str(e)}"),
)

0 comments on commit 3e75dc4

Please sign in to comment.