diff --git a/swh/core/api/serializers.py b/swh/core/api/serializers.py --- a/swh/core/api/serializers.py +++ b/swh/core/api/serializers.py @@ -56,6 +56,7 @@ (PagedResult, "paged_result", _encode_paged_result), # Only for JSON: (bytes, "bytes", lambda o: base64.b85encode(o).decode("ascii")), + (Exception, "exception", lambda e: exception_to_dict(e)), ] DECODERS = { diff --git a/swh/core/api/tests/test_rpc_client_server.py b/swh/core/api/tests/test_rpc_client_server.py --- a/swh/core/api/tests/test_rpc_client_server.py +++ b/swh/core/api/tests/test_rpc_client_server.py @@ -30,6 +30,10 @@ def raise_typeerror(self): raise TypeError("Did I pass through?") + @remote_api_endpoint("raise_exception_chain") + def raise_exception_chain(self): + raise Exception(Exception("error")) + # this class is used on the client part. We cannot inherit from RPCTest # because the automagic metaclass based code that generates the RPCClient @@ -115,3 +119,12 @@ str(exc_info.value) == "" ) + + +def test_api_raise_exception_chain(swh_rpc_client): + with pytest.raises(RemoteException) as exc_info: + swh_rpc_client.post("raise_exception_chain", data={}) + + assert exc_info.value.args[0]["type"] == "Exception" + assert exc_info.value.args[0]["args"][0][b"swhtype"] == "exception" + assert exc_info.value.args[0]["args"][0][b"d"]["exception"]["message"] == "error"