Skip to content

Commit ae8d8a1

Browse files
committed
Move retry-after constant to config.py (#543 review)
1 parent 1d47b7a commit ae8d8a1

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

app/core/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@
4444
for origin in os.getenv("FRONTEND_ORIGINS", _DEFAULT_ORIGINS).split(",")
4545
if origin.strip()
4646
]
47+
48+
# --- Error handling -------------------------------------------------------
49+
# Advisory Retry-After sent to clients on 503 responses. This is a client
50+
# hint, not a measured backpressure value — the app has no queue-depth signal.
51+
RETRY_AFTER_SECONDS = 30

app/core/errors/handlers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
from fastapi.exceptions import RequestValidationError
33
from fastapi.responses import JSONResponse
44

5+
from app.core.config import RETRY_AFTER_SECONDS
56
from app.core.errors.base import AppError
67

7-
# Advisory retry hint on 503 responses — not a measured queue depth or backpressure
8-
# value; just a safe default so clients know when to try again.
9-
_RETRY_AFTER_SECONDS = 30
10-
118

129
def register_exception_handlers(app):
1310
@app.exception_handler(AppError)
@@ -16,7 +13,7 @@ async def app_error_handler(request: Request, exc: AppError):
1613
if exc.detail is not None:
1714
body["detail"] = exc.detail
1815
if exc.status_code == 503:
19-
body["retry_after_seconds"] = _RETRY_AFTER_SECONDS
16+
body["retry_after_seconds"] = RETRY_AFTER_SECONDS
2017
return JSONResponse(status_code=exc.status_code, content=body)
2118

2219
@app.exception_handler(RequestValidationError)

0 commit comments

Comments
 (0)