changeset 7719:04ace15a511e

middleware: introduce more generic VCS webob.exc.HTTPException exception handling
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 08 Jan 2019 13:02:44 +0100
parents 4b41a96416f5
children 7e06657be365
files kallithea/lib/base.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py
diffstat 3 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/base.py	Tue Jan 08 13:02:34 2019 +0100
+++ b/kallithea/lib/base.py	Tue Jan 08 13:02:44 2019 +0100
@@ -308,6 +308,8 @@
             if parsed_request is None:
                 return self.application(environ, start_response)
             return self._handle_request(parsed_request, environ, start_response)
+        except webob.exc.HTTPException as e:
+            return e(environ, start_response)
         finally:
             log = logging.getLogger('kallithea.' + self.__class__.__name__)
             log.debug('Request time: %.3fs', time.time() - start)
--- a/kallithea/lib/middleware/simplegit.py	Tue Jan 08 13:02:34 2019 +0100
+++ b/kallithea/lib/middleware/simplegit.py	Tue Jan 08 13:02:44 2019 +0100
@@ -71,7 +71,7 @@
 
         # quick check if repo exists...
         if not is_valid_repo(parsed_request.repo_name, self.basepath, 'git'):
-            return HTTPNotFound()(environ, start_response)
+            raise HTTPNotFound()
 
         #======================================================================
         # GET ACTION PULL or PUSH
@@ -114,7 +114,7 @@
             return app(environ, start_response)
         except Exception:
             log.error(traceback.format_exc())
-            return HTTPInternalServerError()(environ, start_response)
+            raise HTTPInternalServerError()
 
     def __make_app(self, repo_name):
         """
--- a/kallithea/lib/middleware/simplehg.py	Tue Jan 08 13:02:34 2019 +0100
+++ b/kallithea/lib/middleware/simplehg.py	Tue Jan 08 13:02:44 2019 +0100
@@ -86,15 +86,12 @@
 
         # quick check if repo exists...
         if not is_valid_repo(parsed_request.repo_name, self.basepath, 'hg'):
-            return HTTPNotFound()(environ, start_response)
+            raise HTTPNotFound()
 
         #======================================================================
         # GET ACTION PULL or PUSH
         #======================================================================
-        try:
-            action = self.__get_action(environ)
-        except HTTPBadRequest as e:
-            return e(environ, start_response)
+        action = self.__get_action(environ)
 
         #======================================================================
         # CHECK PERMISSIONS
@@ -135,7 +132,7 @@
             return app(environ, start_response)
         except Exception:
             log.error(traceback.format_exc())
-            return HTTPInternalServerError()(environ, start_response)
+            raise HTTPInternalServerError()
 
     def __make_app(self, repo_name, baseui):
         """