summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-11-05 04:50:59 +0000
committerianb <devnull@localhost>2005-11-05 04:50:59 +0000
commitf4bd738b1cdba4a11e64773a3d4d016cb8e08fa8 (patch)
tree4ed46924b12aa5879b0c6103f7950e33678c917f
parent58c5f2dd2c8a156327c5c0d7ac4df13fb7bca41b (diff)
downloadpaste-f4bd738b1cdba4a11e64773a3d4d016cb8e08fa8.tar.gz
Add a hook to the error middleware to ignore (re-raise) exceptions in env[paste.expected_exceptions]; also made httpexceptions put this in. This way if httpexceptions wraps error middleware, it'll still work
-rw-r--r--paste/exceptions/errormiddleware.py10
-rw-r--r--paste/httpexceptions.py6
2 files changed, 15 insertions, 1 deletions
diff --git a/paste/exceptions/errormiddleware.py b/paste/exceptions/errormiddleware.py
index 781efe5..cc4bd57 100644
--- a/paste/exceptions/errormiddleware.py
+++ b/paste/exceptions/errormiddleware.py
@@ -57,6 +57,13 @@ class ErrorMiddleware(object):
``error_message``:
When debug mode is off, the error message to show to users.
+
+ This also looks for a special key ``'paste.expected_exceptions``,
+ which should be a list of exception classes. When an exception is
+ raised, if it is found in this list then it will be re-raised
+ instead of being caught. This should generally be set by
+ middleware that may (but probably shouldn't be) installed above
+ this middleware, and wants to get certain exceptions.
"""
def __init__(self, application, global_conf=None,
@@ -118,6 +125,9 @@ class ErrorMiddleware(object):
return self.catching_iter(app_iter, environ)
except:
exc_info = sys.exc_info()
+ for expected in environ.get('paste.expected_exceptions', []):
+ if issubclass(exc_info[0], expected):
+ raise
if not started:
start_response('500 Internal Server Error',
[('content-type', 'text/html')],
diff --git a/paste/httpexceptions.py b/paste/httpexceptions.py
index ce3ab79..b01be07 100644
--- a/paste/httpexceptions.py
+++ b/paste/httpexceptions.py
@@ -225,13 +225,17 @@ def middleware(application, global_conf=None):
"""
def start_application(environ, start_response):
+ environ.setdefault('paste.expected_exceptions', []).append(
+ HTTPException)
app_started = []
def checked_start_response(status, headers, exc_info=None):
app_started.append(None)
return start_response(status, headers, exc_info)
try:
- return application(environ, checked_start_response)
+ v = application(environ, checked_start_response)
+ environ['paste.expected_exceptions'].remove(HTTPException)
+ return v
except HTTPException, e:
if environ.get('paste.debug_suppress_httpexceptions'):
raise