fastapi-template/src/exceptions.py

30 lines
670 B
Python
Raw Normal View History

2026-05-13 15:09:59 +01:00
"""
Global exceptions
Exports:
- UnprocessableContentException
- ConflictException
"""
2026-06-15 09:45:55 +01:00
from typing import Optional
from fastapi import HTTPException, status
class UnprocessableContentException(HTTPException):
def __init__(self, message: Optional[str] = None) -> None:
detail = "Unprocessable content" if not message else message
super().__init__(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
detail=detail,
)
class ConflictException(HTTPException):
def __init__(self, message: Optional[str] = None) -> None:
detail = "Conflict" if not message else message
super().__init__(
status_code=status.HTTP_409_CONFLICT,
detail=detail,
)