diff options
author | Helmut Grohne <helmut@subdivi.de> | 2007-04-15 17:48:38 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2007-04-15 17:48:38 +0200 |
commit | 21d54fd261b972bbdb7f4eea267f4696c6958600 (patch) | |
tree | d27a6fed4ed34a1db8569dbecac43b7d55e8cb07 /wsgitools/middlewares.py | |
parent | 2705b415937bca42d2411e04bf9ad27825330090 (diff) | |
download | wsgitools-21d54fd261b972bbdb7f4eea267f4696c6958600.tar.gz |
TracebackMiddleware catches more exceptions
Diffstat (limited to 'wsgitools/middlewares.py')
-rw-r--r-- | wsgitools/middlewares.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/wsgitools/middlewares.py b/wsgitools/middlewares.py index ffb2e38..a0b4a7c 100644 --- a/wsgitools/middlewares.py +++ b/wsgitools/middlewares.py @@ -278,7 +278,17 @@ class TracebackMiddleware: def __call__(self, environ, start_response): """wsgi interface""" try: - return self.app(environ, start_response) + ret = self.app(environ, start_response) + if isinstance(ret, list): + return ret + # Take the first element of the iterator and possibly catch an + # exception there. + ret = iter(ret) + try: + first = ret.next() + except StopIteration: + return CloseableList(getattr(ret, "close", None), []) + return CloseableIterator(getattr(ret, "close", None), [first], ret) except: exc_info = sys.exc_info() data = cgitb.html(exc_info) |