proxy return 500 on unhandled exceptions

This commit is contained in:
Michael Barton 2010-07-19 11:54:11 +00:00
parent 2ee5d7ee9c
commit 62a105d774
2 changed files with 19 additions and 3 deletions

View File

@ -30,7 +30,8 @@ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
HTTPCreated, HTTPLengthRequired, HTTPMethodNotAllowed, HTTPNoContent, \ HTTPCreated, HTTPLengthRequired, HTTPMethodNotAllowed, HTTPNoContent, \
HTTPNotFound, HTTPNotModified, HTTPPreconditionFailed, \ HTTPNotFound, HTTPNotModified, HTTPPreconditionFailed, \
HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, \ HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, \
HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, status_map HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, HTTPServerError, \
status_map
from webob import Request, Response from webob import Request, Response
from swift.common.ring import Ring from swift.common.ring import Ring
@ -1081,9 +1082,9 @@ class BaseApplication(object):
return handler(req) return handler(req)
except AttributeError: except AttributeError:
return HTTPMethodNotAllowed(request=req) return HTTPMethodNotAllowed(request=req)
except: except Exception:
self.logger.exception('ERROR Unhandled exception in request') self.logger.exception('ERROR Unhandled exception in request')
return HTTPServiceUnavailable(request=req) return HTTPServerError(request=req)
def check_rate_limit(self, req, path_parts): def check_rate_limit(self, req, path_parts):
"""Check for rate limiting.""" """Check for rate limiting."""

View File

@ -188,6 +188,21 @@ def save_globals():
# tests # 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): class TestObjectController(unittest.TestCase):
def setUp(self): def setUp(self):