diff --git a/algosdk/error.py b/algosdk/error.py index b0931977..cdc5cff7 100644 --- a/algosdk/error.py +++ b/algosdk/error.py @@ -178,9 +178,10 @@ def __init__(self, msg): class AlgodHTTPError(Exception): - def __init__(self, msg, code=None): + def __init__(self, msg, code=None, j=None): super().__init__(msg) self.code = code + self.json = j class AlgodResponseError(Exception): diff --git a/algosdk/v2client/algod.py b/algosdk/v2client/algod.py index bd2f4189..0c6bee12 100644 --- a/algosdk/v2client/algod.py +++ b/algosdk/v2client/algod.py @@ -105,10 +105,13 @@ def algod_request( except urllib.error.HTTPError as e: code = e.code es = e.read().decode("utf-8") + m = e # If json.loads() fails, we'll return e itself + j = None try: - e = json.loads(es)["message"] + j = json.loads(es) + m = j["message"] finally: - raise error.AlgodHTTPError(e, code) + raise error.AlgodHTTPError(m, code, j) if response_format == "json": try: return json.load(resp)