File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 13
13
BadResponseFormat ,
14
14
BlockNotFound ,
15
15
ContractLogicError ,
16
+ MethodUnavailable ,
16
17
TransactionNotFound ,
17
18
)
18
19
32
33
"message" : "You cannot query logs for more than 10000 blocks at once." ,
33
34
"method" : "eth_getLogs" ,
34
35
}
36
+ METHOD_NOT_FOUND_RESP_FORMAT = {
37
+ "jsonrpc" : "2.0" ,
38
+ "error" : {
39
+ "code" : - 32601 ,
40
+ "message" : "the method eth_getTransactionByHash does not exist/is not "
41
+ "available" ,
42
+ },
43
+ }
35
44
36
45
37
46
def raise_contract_logic_error (response ):
@@ -105,6 +114,13 @@ def raise_contract_logic_error(response):
105
114
raise_transaction_not_found ,
106
115
TransactionNotFound ,
107
116
),
117
+ (
118
+ METHOD_NOT_FOUND_RESP_FORMAT ,
119
+ (),
120
+ identity ,
121
+ identity ,
122
+ MethodUnavailable ,
123
+ ),
108
124
],
109
125
)
110
126
def test_formatted_response_raises_errors (
Original file line number Diff line number Diff line change @@ -287,3 +287,11 @@ class BadResponseFormat(Web3Exception):
287
287
"""
288
288
289
289
pass
290
+
291
+
292
+ class MethodUnavailable (Web3Exception ):
293
+ """
294
+ Raised when the method is not available on the node
295
+ """
296
+
297
+ pass
Original file line number Diff line number Diff line change 34
34
)
35
35
from web3 .exceptions import (
36
36
BadResponseFormat ,
37
+ MethodUnavailable ,
37
38
)
38
39
from web3 .middleware import (
39
40
abi_middleware ,
@@ -188,6 +189,8 @@ def formatted_response(
188
189
) -> Any :
189
190
if "error" in response :
190
191
apply_error_formatters (error_formatters , response )
192
+ if response ["error" ].get ("code" ) == - 32601 :
193
+ raise MethodUnavailable (response ["error" ])
191
194
raise ValueError (response ["error" ])
192
195
# NULL_RESPONSES includes None, so return False here as the default
193
196
# so we don't apply the null_result_formatters if there is no 'result' key
You can’t perform that action at this time.
0 commit comments