Coverage for app/core/exceptions.py: 77%
31 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-02 23:27 +0000
1from fastapi import HTTPException, status
3# Use whenever you want to raise the 404 exception in a service
4# def safe_query_or_404(query_result, message="Resource not found."):
5# if not query_result:
6# raise HTTPException(status_code=404, detail=message)
7# return query_result
9class UserNotFoundError(HTTPException):
10 def __init__(self, detail: str = "Resource not found."):
11 super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
13class UnauthorizedError(HTTPException):
14 def __init__(self, detail: str = "Not authorized."):
15 super().__init__(status_code=status.HTTP_401_UNAUTHORIZED, detail=detail)
17class BadRequestError(HTTPException):
18 def __init__(self, detail: str = "Bad request (invalid input, missing fields, bad data)."):
19 super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
21class InvalidJoinCodeError(HTTPException):
22 def __init__(self, detail: str = "Invalid join code (invalid input, missing fields, bad data)."):
23 super().__init__(status_code=status.HTTP_400_BAD_REQUEST, detail=detail)
25class CampaignNotFoundError(HTTPException):
26 def __init__(self, detail: str = "Campaign not found."):
27 super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
29class WorldNotFoundError(HTTPException):
30 def __init__(self, detail: str = "World not found."):
31 super().__init__(status_code=status.HTTP_404_NOT_FOUND, detail=detail)
33# Use this one if SUPABASE KEY or URL are missing
34class DatabaseQueryError(HTTPException):
35 def __init__(self, detail: str = "Database query error (selects, queries)."):
36 super().__init__(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail)
38class DatabaseSaveError(HTTPException):
39 def __init__(self, detail: str = "Database save error (insert, update, delete)."):
40 super().__init__(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail)
42class MissingCredentialsError(HTTPException):
43 def __init__(self, detail: str = "Credentials missing."):
44 super().__init__(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=detail)
46# Use this when roles are not sufficient
47class ForbiddenActionError(HTTPException):
48 def __init__(self, detail: str = "User is authenticated but not authorized."):
49 super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)