-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
44 lines (39 loc) · 1.08 KB
/
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
37
38
39
40
41
42
43
44
__author__ = "Daksh Patel"
from flask import jsonify
def create_response(status_value, code, message, result=None):
"""
:param status_value: The status for the request (True/False)
:type status_value: bool
:param code: The status code for the request
:type code: int
:param message: The message for the request
:type message: str
:param result: The dictionary containing result for the request (if any)
:type result: dict
:return: A response to send
:rtype: dict
"""
if result is None:
result = {}
resp = {
'status': status_value,
'code': code,
'message': message,
'result': result,
'version': 'v1'
}
resp = jsonify(resp)
resp.headers.add('Access-Control-Allow-Origin', '*')
return resp
def unauthorized_access():
code = 401
status = False
msg = f'Unauthorized access the private resources. Please login'
result = {}
resp = create_response(
status_value=status,
code=code,
message=msg,
result=result
)
return resp