From c0aa69fa230f42ffa13b5a778e1ba4b21f4eefba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 29 Jan 2017 01:11:57 +0100 Subject: [PATCH] Make wsgi app returns Internal Server Error on exception If no protocol convert the data into a Response and if the data is an exception it should be returned as an Internal Server Error instead of a succeed response. The exception can be used as description for the Internal Server Error. issue6201 review31951002 --- trytond/protocols/jsonrpc.py | 2 +- trytond/wsgi.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index 659814290f..d415da9668 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -154,7 +154,7 @@ class JSONProtocol: response['result'] = data else: if isinstance(data, Exception): - return InternalServerError() + return InternalServerError(data) response = data return Response(json.dumps(response, cls=JSONEncoder), content_type='application/json') diff --git a/trytond/wsgi.py b/trytond/wsgi.py index bf19d6e4de..f7672666e4 100644 --- a/trytond/wsgi.py +++ b/trytond/wsgi.py @@ -6,7 +6,7 @@ import traceback from werkzeug.wrappers import Response from werkzeug.routing import Map, Rule -from werkzeug.exceptions import abort, HTTPException +from werkzeug.exceptions import abort, HTTPException, InternalServerError import wrapt @@ -82,7 +82,10 @@ class TrytondWSGI(object): response = cls.response(data, request) break else: - response = Response(data) + if isinstance(data, Exception): + response = InternalServerError(data) + else: + response = Response(data) else: response = data # TODO custom process response