aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/util/wsgi.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2012-08-29 16:24:03 -0400
committerW. Trevor King <wking@tremily.us>2012-08-29 23:29:56 -0400
commit5a32d82284e54facf2f5dcb03ba37afe3805a609 (patch)
tree3252239fcf095bfdf89708fce55cd359b7d9ca52 /libbe/util/wsgi.py
parent2950a115fb106ae73b87f87dc4865156d9311f8e (diff)
downloadbugseverywhere-5a32d82284e54facf2f5dcb03ba37afe3805a609.tar.gz
util:wsgi: add BEExceptionApp for translating storage exceptions.
This fixes .test_get_initial_value for the HTTP backend, because the tests use TestingHTTP.getURL, which only catch HandlerError, not the more specific storage exceptions.
Diffstat (limited to 'libbe/util/wsgi.py')
-rw-r--r--libbe/util/wsgi.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/libbe/util/wsgi.py b/libbe/util/wsgi.py
index 41d625c..e649bac 100644
--- a/libbe/util/wsgi.py
+++ b/libbe/util/wsgi.py
@@ -38,6 +38,8 @@ except ImportError:
import libbe.util.encoding
import libbe.command
import libbe.command.base
+import libbe.storage
+
if libbe.TESTING == True:
import copy
@@ -264,6 +266,25 @@ class ExceptionApp (WSGI_Middleware):
raise
+class BEExceptionApp (WSGI_Middleware):
+ """Translate BE-specific exceptions
+ """
+ def __init__(self, *args, **kwargs):
+ super(BEExceptionApp, self).__init__(*args, **kwargs)
+ self.http_user_error = 418
+
+ def _call(self, environ, start_response):
+ try:
+ return self.app(environ, start_response)
+ except libbe.storage.NotReadable as e:
+ raise libbe.util.wsgi.HandlerError(403, 'Read permission denied')
+ except libbe.storage.NotWriteable as e:
+ raise libbe.util.wsgi.HandlerError(403, 'Write permission denied')
+ except libbe.storage.InvalidID as e:
+ raise libbe.util.wsgi.HandlerError(
+ self.http_user_error, 'InvalidID {}'.format(e))
+
+
class UppercaseHeaderApp (WSGI_Middleware):
"""WSGI middleware that uppercases incoming HTTP headers.
@@ -597,6 +618,7 @@ class ServerCommand (libbe.command.base.Command):
'socket-name':params['host'],
'port':params['port'],
}
+ app = BEExceptionApp(app, logger=self.logger)
app = ExceptionApp(app, logger=self.logger)
if params['ssl'] == True:
details['protocol'] = 'HTTPS'