[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.
This commit is contained in:
parent
3d85eaa591
commit
88cc816670
|
@ -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("<function %s.%s> returns an invalid response type for an http request" % (f.__module__, f.__name__))
|
||||
|
||||
_logger.warn("<function %s.%s> returns an invalid response type for an http request" % (f.__module__, f.__name__))
|
||||
return response
|
||||
response_wrap.routing = routing
|
||||
response_wrap.original_func = f
|
||||
|
|
Loading…
Reference in New Issue