Spaces:
Running
Running
Download src/sonicagent_rt/api/errors.py from ruslanmv/SonicAgent: direct link, hf CLI and curl.
- Browser
- Download file 602 Bytes
-
https://huggingface.co/spaces/ruslanmv/SonicAgent/resolve/main/src/sonicagent_rt/api/errors.py
- Command line
-
hf download hf://spaces/ruslanmv/SonicAgent/src/sonicagent_rt/api/errors.py
-
curl -L -o errors.py https://huggingface.co/spaces/ruslanmv/SonicAgent/resolve/main/src/sonicagent_rt/api/errors.py
602 Bytes
| """JSON error responses for the voice API.""" | |
| from __future__ import annotations | |
| from fastapi.responses import JSONResponse | |
| from sonicagent_rt.stt.errors import SpeechError | |
| def error_response(exc: SpeechError, request_id: str | None) -> JSONResponse: | |
| body: dict[str, object] = {"code": exc.code, "message": exc.message} | |
| if request_id: | |
| body["request_id"] = request_id | |
| headers = {"Cache-Control": "no-store"} | |
| if exc.status_code in {429, 503}: | |
| headers["Retry-After"] = "5" | |
| return JSONResponse(status_code=exc.status_code, content={"error": body}, headers=headers) | |