"""Errors"""
from typing import Sequence, Any
from starlette import status
from starlette.exceptions import HTTPException
[docs]
class BackendError(RuntimeError):
"""Failure from a dependent backend"""
[docs]
class DBError(RuntimeError):
"""Undefined DB error"""
[docs]
class DBFetchError(ValueError, DBError):
"""Various issues when fetching an object that are input dependent"""
[docs]
class NotFound(DBFetchError, HTTPException):
"""Object was not found"""
def __init__(self, *args: Sequence[Any]) -> None:
"""make us also 404 HTTP error"""
self.status_code = status.HTTP_404_NOT_FOUND
self.detail = "Not found"
new_args = [status.HTTP_404_NOT_FOUND] + list(args)
super(HTTPException, self).__init__(*new_args)
[docs]
class Deleted(NotFound):
"""Object was deleted"""
[docs]
class ForbiddenOperation(RuntimeError):
"""Forbidden operation"""
[docs]
class EnrollmentError(Exception):
"""Baseclass for issues with enrollments"""
[docs]
class CallsignReserved(HTTPException, EnrollmentError, ValueError):
"""Callsign is already reserved"""
def __init__(self, *args: Sequence[Any]) -> None:
"""make us also 403 HTTP error"""
self.status_code = status.HTTP_403_FORBIDDEN
self.detail = "Forbidden"
new_args = [status.HTTP_403_FORBIDDEN] + list(args)
super(HTTPException, self).__init__(*new_args)
[docs]
class PoolInactive(EnrollmentError, ForbiddenOperation):
"""Inactive pool forbidden operations"""
[docs]
class TokenReuse(HTTPException, ValueError):
"""Token is already reserved"""
def __init__(self, *args: Sequence[Any]) -> None:
"""make us also 403 HTTP error"""
self.status_code = status.HTTP_403_FORBIDDEN
self.detail = "Forbidden"
new_args = [status.HTTP_403_FORBIDDEN] + list(args)
super(HTTPException, self).__init__(*new_args)