[FIX] http: JsonRequest return code error as status code

+ Manage 404 error, avoiding tb in log and respecting status code
in response request.
This commit is contained in:
Jeremy Kersten
2018-02-01 09:47:25 +01:00
parent 13c326caaa
commit e15a7b4c65
+9 -3
View File
@@ -629,8 +629,9 @@ class JsonRequest(WebRequest):
body = json.dumps(response)
return Response(
body, headers=[('Content-Type', mime),
('Content-Length', len(body))])
body, status=error and error.pop('http_status', 200) or 200,
headers=[('Content-Type', mime), ('Content-Length', len(body))]
)
def _handle_exception(self, exception):
"""Called within an except block to allow converting exceptions
@@ -639,13 +640,18 @@ class JsonRequest(WebRequest):
try:
return super(JsonRequest, self)._handle_exception(exception)
except Exception:
if not isinstance(exception, (odoo.exceptions.Warning, SessionExpiredException, odoo.exceptions.except_orm)):
if not isinstance(exception, (odoo.exceptions.Warning, SessionExpiredException,
odoo.exceptions.except_orm, werkzeug.exceptions.NotFound)):
_logger.exception("Exception during JSON request handling.")
error = {
'code': 200,
'message': "Odoo Server Error",
'data': serialize_exception(exception)
}
if isinstance(exception, werkzeug.exceptions.NotFound):
error['http_status'] = 404
error['code'] = 404
error['message'] = "404: Not Found"
if isinstance(exception, AuthenticationError):
error['code'] = 100
error['message'] = "Odoo Session Invalid"