summaryrefslogtreecommitdiff
path: root/pecan/middleware/errordocument.py
diff options
context:
space:
mode:
Diffstat (limited to 'pecan/middleware/errordocument.py')
-rw-r--r--pecan/middleware/errordocument.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/pecan/middleware/errordocument.py b/pecan/middleware/errordocument.py
index 8a7aeab..22443cc 100644
--- a/pecan/middleware/errordocument.py
+++ b/pecan/middleware/errordocument.py
@@ -36,7 +36,11 @@ class StatusPersist(object):
class ErrorDocumentMiddleware(object):
-
+ '''
+ Intersects HTTP response status code, looks it up in the error map defined
+ in the Pecan app config.py, and routes to the controller assigned to that
+ status.
+ '''
def __init__(self, app, error_map):
self.app = app
self.error_map = error_map
@@ -44,6 +48,10 @@ class ErrorDocumentMiddleware(object):
def __call__(self, environ, start_response):
def replacement_start_response(status, headers, exc_info=None):
+ '''
+ Overrides the default response if the status is defined in the
+ Pecan app error map configuration.
+ '''
try:
status_code = int(status.split(' ')[0])
except (ValueError, TypeError): # pragma: nocover
@@ -60,7 +68,6 @@ class ErrorDocumentMiddleware(object):
self.error_map[status_code]
)
raise ForwardRequestException(factory=factory)
-
return start_response(status, headers, exc_info)
app_iter = self.app(environ, replacement_start_response)