From f2e2ae0599de933a45a4b6e33bd4bbc6340214e9 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 22 Sep 2023 17:29:08 +0200 Subject: [PATCH] Add env var to add an exception logging errorhandler --- README.md | 2 ++ web.py | 6 ++++++ 2 files changed, 8 insertions(+) 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 905cb2c..a5cb7e9 100644 --- a/web.py +++ b/web.py @@ -32,6 +32,12 @@ 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 ## #######################