From 48af63bbb35835e08e1bacbdcfc19568e633704b Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 4 Jul 2019 17:10:56 +0300 Subject: Change: catch exceptions from a wider area --- api.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api.py b/api.py index 7804f9d..47596b7 100755 --- a/api.py +++ b/api.py @@ -132,21 +132,21 @@ class API: def check(self, func, required_scopes, kwargs): '''Call a callback function, if it's OK to do so''' - r = bottle.request - logging.debug('New request, checking access: %s %s', r.method, r.path) + try: + r = bottle.request + logging.debug('New request, checking access: %s %s', r.method, r.path) - if self._checker.access_is_allowed(r.headers, required_scopes): - logging.info('Access is allowed: %s %s', r.method, r.path) - try: + if self._checker.access_is_allowed(r.headers, required_scopes): + logging.info('Access is allowed: %s %s', r.method, r.path) ret = func(**kwargs) - except Exception as e: - logging.warning('Caught exception: %s', str(e)) - return bottle.httpError(500) - logging.info('Result: %r', ret) - return ret - - logging.error('Request denied %s %s', r.method, r.path) - return bottle.HTTPError(400) + logging.info('Result: %r', ret) + return ret + + logging.error('Request denied %s %s', r.method, r.path) + return bottle.HTTPError(400) + except Exception as e: + logging.warning('Caught exception: %s', str(e)) + return bottle.httpError(500) class Controller(API): -- cgit v1.2.1