Handle JSONRPC error codes in web3 providers (#491)
This commit is contained in:
parent
1122daf9a1
commit
5327688a20
@ -1,6 +1,9 @@
|
|||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
const promiseRetry = require('promise-retry')
|
const promiseRetry = require('promise-retry')
|
||||||
|
|
||||||
|
// From EIP-1474 and Infura documentation
|
||||||
|
const JSONRPC_ERROR_CODES = [-32603, -32002, -32005]
|
||||||
|
|
||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
requestTimeout: 0,
|
requestTimeout: 0,
|
||||||
retry: {
|
retry: {
|
||||||
@ -61,6 +64,12 @@ function send(url, payload, options) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
|
.then(response => {
|
||||||
|
if (response.error && JSONRPC_ERROR_CODES.includes(response.error.code)) {
|
||||||
|
throw new Error(response.error.message)
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function trySend(payload, urls, initialIndex, options) {
|
async function trySend(payload, urls, initialIndex, options) {
|
||||||
|
@ -13,7 +13,6 @@ function RedundantHttpListProvider(urls, options = {}) {
|
|||||||
|
|
||||||
this.urls = urls
|
this.urls = urls
|
||||||
this.options = { ...defaultOptions, ...options }
|
this.options = { ...defaultOptions, ...options }
|
||||||
this.currentIndex = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RedundantHttpListProvider.prototype.send = async function send(payload, callback) {
|
RedundantHttpListProvider.prototype.send = async function send(payload, callback) {
|
||||||
|
Loading…
Reference in New Issue
Block a user