-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
37 lines (24 loc) · 939 Bytes
/
utils.py
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
from flask import jsonify
def success_data_jsonify(obj={}, code=200):
response = jsonify({
'success' : True,
'data' : obj
})
response.status_code = code
return response
def error_response(title, message, code):
error_dictionary = {'message' : message,
'title' : title}
response = jsonify({'success' : False,
'error' : error_dictionary
})
response.status_code = code
return response
def invalid_format():
return error_response(title="Invalid request body",
message="You must provide the parameters in the form of a JSON object and set the Content-Type Header",
code=400)
def unauthorized_response():
return error_response(title="No user is logged in",
message="Please login to access this functionality",
code=401)