MethodNotAllowed,
NotFound,
InternalServerError,
+ HTTPException,
)
def configure_exception(app):
+ @app.errorhandler(HTTPException)
+ def default_error_handler(error):
+ '''Default error handler'''
+ status_code = getattr(error, 'code', 500)
+ problem = ProblemDetails(status_code, str(error))
+ return problem.serialize(), status_code
+
+ @app.errorhandler(NotFound)
+ def handle_notfound(error):
+ '''notfound handler'''
+ problem = ProblemDetails(404, str(error))
+ return problem.serialize(), 404
+
@app.errorhandler(BadRequestException)
def handle_badrequest_exception(error):
'''Return a custom message and 400 status code'''
'''Return a custom message and 500 status code'''
problem = ProblemDetails(500, "Internal Server Error")
return problem.serialize(), 500
+
+ @app.errorhandler(Exception)
+ def handle_general_exception(error):
+ '''Return a custom message and 500 status code'''
+ problem = ProblemDetails(500, "Internal Server Error")
+ return problem.serialize(), 500