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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
"""
Code Errors reference:
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
- https://developer.mozilla.org/es/docs/Web/HTTP/Status
"""
import json
from flask import (
Response
)
def internal_server_error(e):
response = Response(
response=json.dumps({
"msg": "Something went wrong",
"_desc": str(e)
}),
status=500,
mimetype="applications/json"
)
return response
def schema_validation_error(e):
response = Response(
response=json.dumps({
"msg": "Request is missing required fields",
"_desc": str(e)
}),
status=400,
mimetype="applications/json"
)
return response
def unauthorized_error(e):
response = Response(
response=json.dumps({
"msg": "Invalid username or password",
"_desc": str(e)
}),
status=401,
mimetype="applications/json"
)
return response
def disable_register_error(e):
response = Response(
response=json.dumps({
"msg": "Unauthorized create user",
"_desc": str(e)
}),
status=401,
mimetype="applications/json"
)
return response
def error_method():
response = Response(
response=json.dumps({
"msg": "Method unauthorized for your user"
}),
status=401,
mimetype="applications/json"
)
return response
# Status 204 does not show any msg
def not_data_found():
response = Response(
status=204,
mimetype="applications/json"
)
return response
# #####
# Heroe
# #####
def heroe_already_exists_error(e):
response = Response(
response=json.dumps({
"msg": "Heroe with given full-name already exists",
"_desc": str(e)
}),
status=400,
mimetype="applications/json"
)
return response
def updating_heroe_error(e):
response = Response(
response=json.dumps({
"msg": "Updating heroe added by other is forbidden",
"_desc": str(e)
}),
status=403,
mimetype="applications/json"
)
return response
def deleting_heroe_error(e):
response = Response(
response=json.dumps({
"msg": "Deleting heroe added by other is forbidden",
"_desc": str(e)
}),
status=403,
mimetype="applications/json"
)
return response
# #####
# User
# #####
def user_already_exists_error(e):
response = Response(
response=json.dumps({
"msg": "User with given username or email already exists",
"_desc": str(e)
}),
status=400,
mimetype="applications/json"
)
return response
def updating_user_error(e):
response = Response(
response=json.dumps({
"msg": "Updating user added by other is forbidden",
"_desc": str(e)
}),
status=403,
mimetype="applications/json"
)
return response
def deleting_user_error(e):
response = Response(
response=json.dumps({
"msg": "Deleting user added by other is forbidden",
"_desc": str(e)
}),
status=403,
mimetype="applications/json"
)
return response
|