/
error_handlers.py
34 lines (26 loc) · 1.22 KB
/
error_handlers.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
"""
Contains all error handling code
"""
from flask import request, Response
from flask.helpers import json
from app import *
__author__ = 'ferron'
@app.errorhandler(401)
def unauthorized_access(error):
return Response(response=json.dumps(dict(error='Unauthorized Access',
statusCode=error.code)),
status=error.code, headers={},
mimetype='application/json', content_type='application/json')
@app.errorhandler(404)
def page_not_found(error):
return Response(response=json.dumps(dict(error='404 Page Not Found',
statusCode=error.code)),
status=error.code, headers={},
mimetype='application/json', content_type='application/json')
@app.errorhandler(405)
def method_not_allowed(error):
return Response(response=json.dumps(dict(error='405 Method Not Allowed',
message='The method {0} is not allowed for the requested URL'.format(request.method),
statusCode=error.code)),
status=error.code, headers={},
mimetype='application/json', content_type='application/json')