INNER CODE UNIT · Python
register_exception_handlers
Kabanosk/whisper-website · src/exceptions.py:19
def register_exception_handlers(app: FastAPI):
"""Register app-wide handlers for transcription and validation errors."""
@app.exception_handler(TranscriptionError)
def handle_transcription_error(request: Request, exc: TranscriptionError) -> JSONResponse:
logger.error("Transcription request failed: {}", exc)
return JSONResponse(status_code=422, content={"detail": str(exc)})
@app.exception_handler(pydantic.ValidationError)
def handle_validation_error(request: Request, exc: pydantic.ValidationError) -> JSONResponse:
logger.error("Bad values in the form. {}", exc)
return JSONResponse(status_code=422, content={"detail": exc.errors()})