"""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