github-actions[bot]
Automated Deploy: 309ee4a1193c878dae3a2f2680172e0f9b7ff5e5
532466c
Raw History Blame Contribute Delete
1.02 kB
"""Reusable HTTP error helpers."""
from fastapi import HTTPException
def bad_request(detail: str, cause: Exception | None = None) -> HTTPException:
exc = HTTPException(status_code=400, detail=detail)
if cause is not None:
raise exc from cause
raise exc
def not_found(detail: str = "Not found.") -> HTTPException:
raise HTTPException(status_code=404, detail=detail)
def conflict(detail: str) -> HTTPException:
raise HTTPException(status_code=409, detail=detail)
def server_error(detail: str) -> HTTPException:
raise HTTPException(status_code=500, detail=detail)
def service_unavailable(detail: str, cause: Exception | None = None) -> HTTPException:
exc = HTTPException(status_code=503, detail=detail)
if cause is not None:
raise exc from cause
raise exc
def bad_gateway(detail: str, cause: Exception | None = None) -> HTTPException:
exc = HTTPException(status_code=502, detail=detail)
if cause is not None:
raise exc from cause
raise exc