diff --git a/README.md b/README.md index d71e2d0..0c1eaae 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,8 @@ my-python: - `MODE` to specify the deployment mode. Can be `development` as well as `production`. Defaults to `production` +- `LOG_EXCEPTIONS` set to any value to add a catch-all Flask errorhandler that logs exceptions rather than just returning them, to aid with debugging. Is not on by default in development as it may prevent custom errorhandlers in you app from being reached. + - `MU_SPARQL_ENDPOINT` is used to configure the SPARQL endpoint. - By default this is set to `http://database:8890/sparql`. In that case the triple store used in the backend should be linked to the microservice container as `database`. diff --git a/web.py b/web.py index 813c9b2..a5cb7e9 100644 --- a/web.py +++ b/web.py @@ -29,8 +29,14 @@ try: module_path = 'ext.app.{}'.format(app_file) import_module(module_path) -except Exception as e: - helpers.log(str(e)) +except Exception: + helpers.logger.exception('Exception raised when importing app code') + +if os.environ.get('LOG_EXCEPTIONS'): + @app.errorhandler(Exception) + def handle_exception(e): + helpers.logger.exception('Unhandled exception raised in route, returning 500') + raise e ####################### ## Start Application ##