-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_errors.py
More file actions
executable file
·67 lines (61 loc) · 1.59 KB
/
my_errors.py
File metadata and controls
executable file
·67 lines (61 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/local/bin/python3
"""
This module provides HTTPException classses which can be raised
To add an error, add its name, message and status to the dict
'errors' below
To include;
import my_errors
my_errors.make_classes(my_errors.errors)
"""
# ----- Errors -----
from flask_restful import HTTPException
errors = {
'not_found': {
'message': "Not Found",
'status': 404,
},
'user_not_found': {
'message': 'User Not Found',
'status': 404,
},
'user_exists': {
'message': 'User already exists',
'status': 400,
},
'file_exists': {
'message': 'File already exists',
'status': 400,
},
'bad_request': {
'message': 'Bad Request',
'status': 400,
},
'unauthorized': {
'message': 'Unauthorized Access',
'status': 403,
},
'unauthorized_bad_sig': {
'message': 'Unauthorized Access: Bad Signature',
'status': 403,
},
'unauthorized_sig_expired': {
'message': 'Unauthorized Access: Signature Expired',
'status': 403,
},
'unauthorized_user_not_found': {
'message': 'Unauthorized Access: User not found',
'status': 403,
},
'unauthorized_bad_password': {
'message': 'Unauthorized Access: Bad password',
'status': 403,
},
'unauthorized_bad_request': {
'message': 'Unauthorized Access: Bad request',
'status': 403,
},
}
def make_classes(errors):
"""Generate the error classes"""
for key in errors:
globals()[key] = type(key, (HTTPException, ), {'code': 400})