[FIX] request.handle_exception: cleanup override logic, fixed chain broken by commit a096ae0

handle_exception() is supposed to try handling an exception and if it cannot,
re-raise it. Overridden methods must therefore call super() within a try/except
block, and only attempt to handle the exception if super() raised.
This commit is contained in:
Denis Ledoux 2014-05-23 13:15:52 +02:00
parent 7a3b7f7fe2
commit 51c7b55da0
2 changed files with 52 additions and 47 deletions

View File

@ -99,9 +99,9 @@ class ir_http(orm.AbstractModel):
werkzeug.exceptions.abort(werkzeug.utils.redirect(url))
def _handle_exception(self, exception=None, code=500):
res = super(ir_http, self)._handle_exception(exception)
if isinstance(exception, werkzeug.exceptions.HTTPException) and hasattr(exception, 'response') and exception.response:
return exception.response
try:
return super(ir_http, self)._handle_exception(exception)
except Exception:
if getattr(request, 'website_enabled', False) and request.website:
values = dict(
exception=exception,
@ -137,7 +137,7 @@ class ir_http(orm.AbstractModel):
html = request.website._render('website.http_error', values)
return werkzeug.wrappers.Response(html, status=code, content_type='text/html;charset=utf-8')
return res
raise
class ModelConverter(ir.ir_http.ModelConverter):
def __init__(self, url_map, model=False):

View File

@ -208,6 +208,9 @@ class WebRequest(object):
to abitrary responses. Anything returned (except None) will
be used as response."""
self._failed = exception # prevent tx commit
if isinstance(exception, werkzeug.exceptions.HTTPException):
return exception
raise
def _call_function(self, *args, **kwargs):
request = self
@ -374,7 +377,9 @@ class JsonRequest(WebRequest):
"""Called within an except block to allow converting exceptions
to abitrary responses. Anything returned (except None) will
be used as response."""
super(JsonRequest, self)._handle_exception(exception)
try:
return super(JsonRequest, self)._handle_exception(exception)
except Exception:
_logger.exception("Exception during JSON request handling.")
error = {
'code': 200,