From 49c08cba105c87d55b5001aba36e010fdcf29b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 6 Sep 2016 17:10:50 +0200 Subject: [PATCH] Custom error handlers: also properly handle non-Werkzeug exceptions. --- pillar/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pillar/__init__.py b/pillar/__init__.py index c37a63ba..c7fb9ebc 100644 --- a/pillar/__init__.py +++ b/pillar/__init__.py @@ -286,6 +286,12 @@ class PillarServer(Eve): def pillar_error_handler(self, error_ob): + # 'error_ob' can be any exception. If it's not a Werkzeug exception, + # handle it as a 500. + if not hasattr(error_ob, 'code'): + error_ob.code = 500 + error_ob.description = str(error_ob) + if request.full_path.startswith('/%s/' % self.config['URL_PREFIX']): from pillar.api.utils import jsonify # This is an API request, so respond in JSON.