From 88cc816670d4f864aecd574f45de215067a29626 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 29 Jan 2015 16:15:36 +0100 Subject: [PATCH] [IMP] http: don't warn when using HTTPException results When returning an HTTPException e.g. by calling ``request.not_found()`` which returns a ``werkzeug.exceptions.NotFound()``, the http system would log a warning as HTTPException is neither a subclass of Odoo's Response nor a subclass of werkzeug's BaseResponse. Move the string response case about (for flow clarity), and convert HTTPException instances to Werkzeug responses then fall into the normal BaseResponse -> Response case to ultimately get an Odoo response object out of the HTTPException instance. --- openerp/http.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openerp/http.py b/openerp/http.py index 1d35c989143..64023602d9d 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -396,14 +396,18 @@ def route(route=None, **kw): response = f(*args, **kw) if isinstance(response, Response) or f.routing_type == 'json': return response - elif isinstance(response, werkzeug.wrappers.BaseResponse): + + if isinstance(response, basestring): + return Response(response) + + if isinstance(response, werkzeug.exceptions.HTTPException): + response = response.get_response() + if isinstance(response, werkzeug.wrappers.BaseResponse): response = Response.force_type(response) response.set_default() return response - elif isinstance(response, basestring): - return Response(response) - else: - _logger.warn(" returns an invalid response type for an http request" % (f.__module__, f.__name__)) + + _logger.warn(" returns an invalid response type for an http request" % (f.__module__, f.__name__)) return response response_wrap.routing = routing response_wrap.original_func = f