From 872fdbf519988012893550c9fc6bd1c1a5d44639 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:06:01 +0100 Subject: [PATCH] catch json error (#660) --- cashu/wallet/wallet_deprecated.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cashu/wallet/wallet_deprecated.py b/cashu/wallet/wallet_deprecated.py index fc6326e..5f55544 100644 --- a/cashu/wallet/wallet_deprecated.py +++ b/cashu/wallet/wallet_deprecated.py @@ -1,3 +1,4 @@ +import json from posixpath import join from typing import List, Optional, Tuple, Union @@ -106,7 +107,12 @@ class LedgerAPIDeprecated(SupportsHttpxClient, SupportsMintURL): Raises: Exception: if the response contains an error """ - resp_dict = resp.json() + try: + resp_dict = resp.json() + except json.JSONDecodeError: + # if we can't decode the response, raise for status + resp.raise_for_status() + return if "detail" in resp_dict: logger.trace(f"Error from mint: {resp_dict}") error_message = f"Mint Error: {resp_dict['detail']}"