From 392e4c5f68127a92cb7d5e074cc077a5c7f7c448 Mon Sep 17 00:00:00 2001 From: Romuald Juchnowicz-Bierbasz Date: Thu, 19 Sep 2019 11:17:01 +0200 Subject: [PATCH] Print error data in import notifications --- src/galaxy/api/jsonrpc.py | 19 ++++++++++++------- src/galaxy/api/plugin.py | 10 ++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/galaxy/api/jsonrpc.py b/src/galaxy/api/jsonrpc.py index 8b14ca7..bd5ab64 100644 --- a/src/galaxy/api/jsonrpc.py +++ b/src/galaxy/api/jsonrpc.py @@ -18,6 +18,17 @@ class JsonRpcError(Exception): def __eq__(self, other): return self.code == other.code and self.message == other.message and self.data == other.data + def json(self): + obj = { + "code": self.code, + "message": self.message + } + + if self.data is not None: + obj["error"]["data"] = self.data + + return obj + class ParseError(JsonRpcError): def __init__(self): super().__init__(-32700, "Parse error") @@ -232,15 +243,9 @@ class Server(): response = { "jsonrpc": "2.0", "id": request_id, - "error": { - "code": error.code, - "message": error.message - } + "error": error.json() } - if error.data is not None: - response["error"]["data"] = error.data - self._send(response) @staticmethod diff --git a/src/galaxy/api/plugin.py b/src/galaxy/api/plugin.py index 6badaed..e2330bb 100644 --- a/src/galaxy/api/plugin.py +++ b/src/galaxy/api/plugin.py @@ -331,10 +331,7 @@ class Plugin: def _game_achievements_import_failure(self, game_id: str, error: ApplicationError) -> None: params = { "game_id": game_id, - "error": { - "code": error.code, - "message": error.message - } + "error": error.json() } self._notification_client.notify("game_achievements_import_failure", params) @@ -398,10 +395,7 @@ class Plugin: def _game_time_import_failure(self, game_id: str, error: ApplicationError) -> None: params = { "game_id": game_id, - "error": { - "code": error.code, - "message": error.message - } + "error": error.json() } self._notification_client.notify("game_time_import_failure", params)