From c09e62eed2c7dc1b6933933b6eba78981a0d133e Mon Sep 17 00:00:00 2001 From: daveusa <109542778+alteralt@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:00:29 +0300 Subject: [PATCH] Add exception TransactionNotFoundError in get_transaction_details method --- blockcypher/api.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/blockcypher/api.py b/blockcypher/api.py index 5539f0e..568f0e1 100644 --- a/blockcypher/api.py +++ b/blockcypher/api.py @@ -53,11 +53,19 @@ ''' -class RateLimitError(RuntimeError): +class BlockcypherAPIError(Exception): + pass + + +class RateLimitError(BlockcypherAPIError): ''' Raised when the library makes too many API calls ''' pass +class TransactionNotFoundError(BlockcypherAPIError): + pass + + def get_valid_json(request, allow_204=False): if request.status_code == 429: raise RateLimitError('Status Code 429', request.text) @@ -464,6 +472,10 @@ def get_transaction_details(tx_hash, coin_symbol='btc', limit=None, tx_input_off # format this string as a datetime object response_dict['received'] = parser.parse(response_dict['received']) + if "error" in response_dict: + if response_dict["error"].startswith("Transaction") and response_dict["error"].endswith("not found."): + raise TransactionNotFoundError(response_dict["error"]) + return response_dict