Skip to content

Commit

Permalink
Add MultipleFailedRequests for multiple failed requests for similar data
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed May 25, 2022
1 parent c074dac commit d7fcac8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 7 additions & 2 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
ContractLogicError,
InvalidAddress,
InvalidTransaction,
MultipleFailedRequests,
NameNotFound,
OffchainLookup,
TimeExhausted,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions web3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion web3/utils/async_exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
to_hex_if_bytes,
)
from web3.exceptions import (
MultipleFailedRequests,
ValidationError,
)
from web3.types import (
Expand Down Expand Up @@ -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.")
3 changes: 2 additions & 1 deletion web3/utils/exception_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
to_hex_if_bytes,
)
from web3.exceptions import (
MultipleFailedRequests,
ValidationError,
)
from web3.types import (
Expand Down Expand Up @@ -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.")

0 comments on commit d7fcac8

Please sign in to comment.