diff --git a/swift/common/middleware/catch_errors.py b/swift/common/middleware/catch_errors.py index afb2ea6120..15c0814633 100644 --- a/swift/common/middleware/catch_errors.py +++ b/swift/common/middleware/catch_errors.py @@ -14,7 +14,6 @@ # limitations under the License. from swift import gettext_ as _ -from eventlet import Timeout from swift.common.swob import Request, HTTPServerError from swift.common.utils import get_logger, generate_trans_id @@ -35,8 +34,8 @@ class CatchErrorsContext(WSGIContext): try: # catch any errors in the pipeline resp = self._app_call(env) - except (Exception, Timeout) as err: - self.logger.exception(_('Error: %s'), err) + except: # noqa + self.logger.exception(_('Error: An error occurred')) resp = HTTPServerError(request=Request(env), body='An error occurred', content_type='text/plain') diff --git a/test/unit/common/middleware/test_except.py b/test/unit/common/middleware/test_except.py index 48ad583ccb..5278980559 100644 --- a/test/unit/common/middleware/test_except.py +++ b/test/unit/common/middleware/test_except.py @@ -20,6 +20,10 @@ from swift.common.middleware import catch_errors from swift.common.utils import get_logger +class StrangeException(BaseException): + pass + + class FakeApp(object): def __init__(self, error=False, body_iter=None): @@ -30,6 +34,8 @@ class FakeApp(object): if 'swift.trans_id' not in env: raise Exception('Trans id should always be in env') if self.error: + if self.error == 'strange': + raise StrangeException('whoa') raise Exception('An error occurred') if self.body_iter is None: return ["FAKE APP"] @@ -97,6 +103,12 @@ class TestCatchErrors(unittest.TestCase): app(req.environ, start_response) self.assertTrue(self.logger.txn_id.endswith('-stuff')) + def test_catcherrors_with_unexpected_error(self): + app = catch_errors.CatchErrorMiddleware(FakeApp(error='strange'), {}) + req = Request.blank('/', environ={'REQUEST_METHOD': 'GET'}) + resp = app(req.environ, start_response) + self.assertEquals(list(resp), ['An error occurred']) + if __name__ == '__main__': unittest.main()