-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.py
More file actions
30 lines (20 loc) · 758 Bytes
/
errors.py
File metadata and controls
30 lines (20 loc) · 758 Bytes
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
from flask import jsonify
class EndpointError(Exception):
""" Endpoint error definition"""
def __init__(self, message, status_code):
super().__init__(message)
self.status_code = status_code
def handle_endpoint_error(error):
""" Handling endpoint errors """
response = jsonify({'error': str(error)})
response.status_code = error.status_code
return response
def not_found_error(error):
""" Handling Not Found error"""
return jsonify({"error": "Not found"}), 404
def bad_request_error(error):
""" Handling bad request error """
return jsonify({"error": "Bad request"}), 400
def unauthorized_error(error):
""" Handling unathorized error """
return jsonify({"error": "Unauthorized"}), 401