Better handle missing error.message
This commit is contained in:
parent
04bed170a0
commit
63336757d4
1 changed files with 7 additions and 3 deletions
|
|
@ -2,8 +2,6 @@ from flask import jsonify
|
||||||
from werkzeug.exceptions import default_exceptions
|
from werkzeug.exceptions import default_exceptions
|
||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
class JSONExceptionHandler(object):
|
class JSONExceptionHandler(object):
|
||||||
|
|
||||||
def __init__(self, app=None):
|
def __init__(self, app=None):
|
||||||
|
|
@ -11,7 +9,13 @@ class JSONExceptionHandler(object):
|
||||||
self.init_app(app)
|
self.init_app(app)
|
||||||
|
|
||||||
def std_handler(self, error):
|
def std_handler(self, error):
|
||||||
message = error.description if isinstance(error, HTTPException) else error.message
|
if isinstance(error, HTTPException):
|
||||||
|
message = error.description
|
||||||
|
elif hasattr(error, 'message'):
|
||||||
|
message = error.message
|
||||||
|
else:
|
||||||
|
message = str(error)
|
||||||
|
|
||||||
status_code = error.code if isinstance(error, HTTPException) else 500
|
status_code = error.code if isinstance(error, HTTPException) else 500
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue