-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
51 lines (40 loc) · 1.44 KB
/
Copy pathexceptions.py
File metadata and controls
51 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fastapi import HTTPException, status
class CustomHTTPException(HTTPException):
def __init__(self, status_code: int, detail: str, headers: dict = None):
super().__init__(status_code=status_code, detail=detail, headers=headers)
# General file upload exceptions
file_size_limit_exception = CustomHTTPException(
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
detail="File size exceeds the limit"
)
file_extension_exception = CustomHTTPException(
status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
detail="Invalid file extension"
)
# Custom business logic exceptions for file uploads
invalid_file_format_exception = CustomHTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid file format"
)
file_not_uploaded_exception = CustomHTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="File not uploaded"
)
# Add these to your existing exceptions
duplicate_record_exception = CustomHTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="Record already exists.",
headers={"WWW-Authenticate": "Bearer"},
)
expired_token_exception = CustomHTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail='Token expired'
)
invalid_token_exception = CustomHTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail='Invalid token'
)
not_found_exception = CustomHTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Record not found"
)