From 52c8596c92bbc27b3f102a0945b3fc27197d41bd Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 24 Nov 2016 17:09:56 +0000 Subject: [PATCH] Add application level error handler. This should catch any unexcpeted exceptions. --- app/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 73082d14e..9e275bdfd 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -132,6 +132,12 @@ def init_app(app): response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') return response + @app.errorhandler(Exception) + def exception(error): + app.logger.exception(error) + # error.code is set for our exception types. + return jsonify(result='error', message=error.message), error.code or 500 + @app.errorhandler(404) def page_not_found(e): msg = e.description or "Not found"