Spaces:
Sleeping
Sleeping
File size: 1,399 Bytes
f500072 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import redis.exceptions
from fastapi import Request
from fastapi.responses import JSONResponse
async def redis_connection_error_handler(
request: Request,
exc: redis.exceptions.ConnectionError,
):
return JSONResponse(
status_code=503,
content={
"error": "service_unavailable",
"message": (
"Storage backend is unreachable. "
"If this persists, the service may have exhausted "
"its monthly network quota — check the Redis Cloud dashboard."
),
"action": "retry_later",
},
headers={"Retry-After": "3600"},
)
async def redis_timeout_error_handler(
request: Request,
exc: redis.exceptions.TimeoutError,
):
return JSONResponse(
status_code=504,
content={
"error": "gateway_timeout",
"message": "Storage backend did not respond in time.",
"action": "retry_later",
},
headers={"Retry-After": "30"},
)
async def redis_error_handler(
request: Request,
exc: redis.exceptions.RedisError,
):
return JSONResponse(
status_code=503,
content={
"error": "storage_error",
"message": "A storage error occurred. Please try again later.",
"action": "retry_later",
},
headers={"Retry-After": "60"},
)
|