Skip to content

Commit

Permalink
improve error-handling (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
k9ert authored May 16, 2024
1 parent c4795ac commit 1ab1dbc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/cryptoadvance/spectrum/elsock.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,15 @@ def call(self, method, params=[]) -> dict:
f"Timeout in call ({self._call_timeout} seconds) waiting for {method} on {self._socket}"
)
res = self._results.pop(uid)
if "error" in res:
if "code" in res["error"] and "message" in res["error"]:
raise RPCError(res["error"]["message"], res["error"]["code"])
else:
raise SpectrumInternalException(res)
if isinstance(res, dict) and "error" in res:
error = res.get("error", {})
error_code = error.get("code")
error_message = error.get("message")
if error_code is not None and error_message is not None:
raise RPCError(error_message, error_code)
if "result" in res:
return res["result"]
raise SpectrumInternalException(res)

def ping(self):
start = time.time()
Expand Down

0 comments on commit 1ab1dbc

Please sign in to comment.