proxy return 500 on unhandled exceptions
This commit is contained in:
parent
2ee5d7ee9c
commit
62a105d774
@ -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."""
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user