From 62a105d774db7f29a0fa0e34eaf41fee6139963f Mon Sep 17 00:00:00 2001 From: Michael Barton Date: Mon, 19 Jul 2010 11:54:11 +0000 Subject: [PATCH] proxy return 500 on unhandled exceptions --- swift/proxy/server.py | 7 ++++--- test/unit/proxy/test_server.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 102afa68e6..237ecd2f11 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -30,7 +30,8 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ HTTPCreated, HTTPLengthRequired, HTTPMethodNotAllowed, HTTPNoContent, \ HTTPNotFound, HTTPNotModified, HTTPPreconditionFailed, \ HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, \ - HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, status_map + HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, HTTPServerError, \ + status_map from webob import Request, Response from swift.common.ring import Ring @@ -1081,9 +1082,9 @@ class BaseApplication(object): return handler(req) except AttributeError: return HTTPMethodNotAllowed(request=req) - except: + except Exception: self.logger.exception('ERROR Unhandled exception in request') - return HTTPServiceUnavailable(request=req) + return HTTPServerError(request=req) def check_rate_limit(self, req, path_parts): """Check for rate limiting.""" diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 278cc8158d..e78fddc425 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -188,6 +188,21 @@ def save_globals(): # tests + +class TestProxyServer(unittest.TestCase): + + def test_unhandled_exception(self): + class MyApp(proxy_server.Application): + def get_controller(self, path): + raise Exception('this shouldnt be caught') + app = MyApp(None, FakeMemcache(), account_ring=FakeRing(), + container_ring=FakeRing(), object_ring=FakeRing()) + req = Request.blank('/account', environ={'REQUEST_METHOD': 'HEAD'}) + req.account = 'account' + resp = app.handle_request(req) + self.assertEquals(resp.status_int, 500) + + class TestObjectController(unittest.TestCase): def setUp(self):