room-visualizer-v2 / errors.py
github-actions[bot]
Automated Deploy: 493daa301f7f4360c6f8a09b665c70b6c12463cd
790d9ba
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