From 922c420fae496acd9ff9655647c6bf3a0aa4228e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 17 Nov 2019 17:36:07 +0100 Subject: [PATCH] Return bad request for Tryton exception instead of internal error Those exceptions are expected behavior so it is the fault of the client, not the server. issue8768 review276221002 --- CHANGELOG | 1 + trytond/protocols/jsonrpc.py | 4 +++- trytond/protocols/xmlrpc.py | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d78739e40b..58bc69dc54 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Return 400 instead of 500 for Tryton exception * Fill the reverse field in the One2Many setter * Drop support for skiptest attribute on xml files * Remove implicit field names in ModelStorage.search_read diff --git a/trytond/protocols/jsonrpc.py b/trytond/protocols/jsonrpc.py index 3f03a3aaea..7c876da521 100644 --- a/trytond/protocols/jsonrpc.py +++ b/trytond/protocols/jsonrpc.py @@ -153,7 +153,9 @@ class JSONProtocol: else: response['result'] = data else: - if isinstance(data, Exception): + if isinstance(data, TrytonException): + return BadRequest(data) + elif isinstance(data, Exception): return InternalServerError(data) response = data return Response(json.dumps( diff --git a/trytond/protocols/xmlrpc.py b/trytond/protocols/xmlrpc.py index f2a35e64d1..0a238a3412 100644 --- a/trytond/protocols/xmlrpc.py +++ b/trytond/protocols/xmlrpc.py @@ -153,6 +153,8 @@ class XMLProtocol: data, methodresponse=True, allow_none=True), content_type='text/xml') else: - if isinstance(data, Exception): + if isinstance(data, TrytonException): + return BadRequest(data) + elif isinstance(data, Exception): return InternalServerError(data) return Response(data)