forked from sr2/cloud-api
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""
|
|
Global exceptions
|
|
|
|
Exports:
|
|
- UnprocessableContentException
|
|
- ConflictException
|
|
"""
|
|
|
|
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,
|
|
)
|
|
|
|
|
|
class ForbiddenException(HTTPException):
|
|
def __init__(self, message: Optional[str] = None) -> None:
|
|
detail = "Forbidden" if not message else message
|
|
super().__init__(
|
|
status_code=status.HTTP_403_FORBIDDEN,
|
|
detail=detail,
|
|
)
|
|
|
|
|
|
class UnauthorizedException(HTTPException):
|
|
def __init__(self, message: Optional[str] = None) -> None:
|
|
detail = "Not authorized" if not message else message
|
|
super().__init__(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail=detail,
|
|
)
|