diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 850429a76d..e8aead57c9 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -54,6 +54,7 @@ ContractLogicError, InvalidAddress, InvalidTransaction, + MultipleFailedRequests, NameNotFound, OffchainLookup, TimeExhausted, @@ -904,7 +905,9 @@ async def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( self, async_w3: "Web3", offchain_lookup_contract: "Contract", ) -> None: # GET and POST requests should fail since responses are not mocked - with pytest.raises(Exception, match="Offchain lookup failed for supplied urls"): + with pytest.raises( + MultipleFailedRequests, match="Offchain lookup failed for supplied urls" + ): # TODO: change to contract call when async Contract is supported tx = { 'to': offchain_lookup_contract.address, @@ -2598,7 +2601,9 @@ def test_eth_call_offchain_lookup_raises_when_all_supplied_urls_fail( self, w3: "Web3", offchain_lookup_contract: "Contract", ) -> None: # GET and POST requests should fail since responses are not mocked - with pytest.raises(Exception, match="Offchain lookup failed for supplied urls"): + with pytest.raises( + MultipleFailedRequests, match="Offchain lookup failed for supplied urls" + ): offchain_lookup_contract.functions.testOffchainLookup( OFFCHAIN_LOOKUP_TEST_DATA ).call() diff --git a/web3/exceptions.py b/web3/exceptions.py index 4712a325f1..559ed1f457 100644 --- a/web3/exceptions.py +++ b/web3/exceptions.py @@ -41,6 +41,14 @@ class TooManyRequests(Exception): pass +class MultipleFailedRequests(Exception): + """ + Raised by a provider to signal that multiple requests to retrieve the same (or similar) data + have failed. + """ + pass + + class InvalidAddress(ValueError): """ The supplied address does not have a valid checksum, as defined in EIP-55 diff --git a/web3/utils/async_exception_handling.py b/web3/utils/async_exception_handling.py index 259791e57b..28094d32c8 100644 --- a/web3/utils/async_exception_handling.py +++ b/web3/utils/async_exception_handling.py @@ -20,6 +20,7 @@ to_hex_if_bytes, ) from web3.exceptions import ( + MultipleFailedRequests, ValidationError, ) from web3.types import ( @@ -88,4 +89,4 @@ async def async_handle_offchain_lookup( ]) return encoded_data_with_function_selector - raise Exception("Offchain lookup failed for supplied urls.") + raise MultipleFailedRequests("Offchain lookup failed for supplied urls.") diff --git a/web3/utils/exception_handling.py b/web3/utils/exception_handling.py index 4417920069..dddde1d5eb 100644 --- a/web3/utils/exception_handling.py +++ b/web3/utils/exception_handling.py @@ -19,6 +19,7 @@ to_hex_if_bytes, ) from web3.exceptions import ( + MultipleFailedRequests, ValidationError, ) from web3.types import ( @@ -87,4 +88,4 @@ def handle_offchain_lookup( ]) return encoded_data_with_function_selector - raise Exception("Offchain lookup failed for supplied urls.") + raise MultipleFailedRequests("Offchain lookup failed for supplied urls.")