From f6ca90d5b64e6b1f1e8877adb40a6f515313796f Mon Sep 17 00:00:00 2001 From: Sebastian Pape Date: Fri, 8 Sep 2023 08:31:14 +0200 Subject: [PATCH] v10.18.2: handle failing chunk requests (evm) --- dist/esm/index.evm.js | 68 +++++++++++++++++++--------------- dist/esm/index.js | 68 +++++++++++++++++++--------------- dist/umd/index.evm.js | 68 +++++++++++++++++++--------------- dist/umd/index.js | 68 +++++++++++++++++++--------------- package.evm.json | 2 +- package.json | 2 +- package.solana.json | 2 +- src/clients/ethers/provider.js | 64 ++++++++++++++++++-------------- 8 files changed, 191 insertions(+), 151 deletions(-) diff --git a/dist/esm/index.evm.js b/dist/esm/index.evm.js index b302c2a..67c0493 100644 --- a/dist/esm/index.evm.js +++ b/dist/esm/index.evm.js @@ -80,38 +80,46 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } requestChunk(chunk, endpoint) { - - const request = chunk.map((inflight) => inflight.request); - - return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) - .then((result) => { - // For each result, feed it to the correct Promise, depending - // on whether it was a success or error - chunk.forEach((inflightRequest, index) => { - const payload = result[index]; - if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) { - const error = new Error(payload.error.message); - error.code = payload.error.code; - error.data = payload.error.data; - inflightRequest.reject(error); - } else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) { - inflightRequest.resolve(payload.result); + + try { + + const request = chunk.map((inflight) => inflight.request); + return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) + .then((result) => { + // For each result, feed it to the correct Promise, depending + // on whether it was a success or error + chunk.forEach((inflightRequest, index) => { + const payload = result[index]; + if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) { + const error = new Error(payload.error.message); + error.code = payload.error.code; + error.data = payload.error.data; + inflightRequest.reject(error); + } else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) { + inflightRequest.resolve(payload.result); + } else { + inflightRequest.reject(); + } + }); + }).catch((error) => { + if(error && error.code == 'SERVER_ERROR') { + const index = this._endpoints.indexOf(this._endpoint)+1; + this._failover(); + this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; + this.requestChunk(chunk, this._endpoint); } else { - inflightRequest.reject(); + chunk.forEach((inflightRequest) => { + inflightRequest.reject(error); + }); } - }); - }).catch((error) => { - if(error && error.code == 'SERVER_ERROR') { - const index = this._endpoints.indexOf(this._endpoint)+1; - this._failover(); - this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; - this.requestChunk(chunk, this._endpoint); - } else { - chunk.forEach((inflightRequest) => { - inflightRequest.reject(error); - }); - } - }) + }) + + } catch (e) { + + chunk.forEach((inflightRequest) => { + inflightRequest.reject(); + }); + } } send(method, params) { diff --git a/dist/esm/index.js b/dist/esm/index.js index 3805f95..ac19a07 100644 --- a/dist/esm/index.js +++ b/dist/esm/index.js @@ -46,38 +46,46 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } requestChunk(chunk, endpoint) { - - const request = chunk.map((inflight) => inflight.request); - - return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) - .then((result) => { - // For each result, feed it to the correct Promise, depending - // on whether it was a success or error - chunk.forEach((inflightRequest, index) => { - const payload = result[index]; - if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { - const error = new Error(payload.error.message); - error.code = payload.error.code; - error.data = payload.error.data; - inflightRequest.reject(error); - } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { - inflightRequest.resolve(payload.result); + + try { + + const request = chunk.map((inflight) => inflight.request); + return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) + .then((result) => { + // For each result, feed it to the correct Promise, depending + // on whether it was a success or error + chunk.forEach((inflightRequest, index) => { + const payload = result[index]; + if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { + const error = new Error(payload.error.message); + error.code = payload.error.code; + error.data = payload.error.data; + inflightRequest.reject(error); + } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { + inflightRequest.resolve(payload.result); + } else { + inflightRequest.reject(); + } + }); + }).catch((error) => { + if(error && error.code == 'SERVER_ERROR') { + const index = this._endpoints.indexOf(this._endpoint)+1; + this._failover(); + this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; + this.requestChunk(chunk, this._endpoint); } else { - inflightRequest.reject(); + chunk.forEach((inflightRequest) => { + inflightRequest.reject(error); + }); } - }); - }).catch((error) => { - if(error && error.code == 'SERVER_ERROR') { - const index = this._endpoints.indexOf(this._endpoint)+1; - this._failover(); - this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; - this.requestChunk(chunk, this._endpoint); - } else { - chunk.forEach((inflightRequest) => { - inflightRequest.reject(error); - }); - } - }) + }) + + } catch (e) { + + chunk.forEach((inflightRequest) => { + inflightRequest.reject(); + }); + } } send(method, params) { diff --git a/dist/umd/index.evm.js b/dist/umd/index.evm.js index 1da632c..6616de6 100644 --- a/dist/umd/index.evm.js +++ b/dist/umd/index.evm.js @@ -87,38 +87,46 @@ } requestChunk(chunk, endpoint) { - - const request = chunk.map((inflight) => inflight.request); - - return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request)) - .then((result) => { - // For each result, feed it to the correct Promise, depending - // on whether it was a success or error - chunk.forEach((inflightRequest, index) => { - const payload = result[index]; - if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) { - const error = new Error(payload.error.message); - error.code = payload.error.code; - error.data = payload.error.data; - inflightRequest.reject(error); - } else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) { - inflightRequest.resolve(payload.result); + + try { + + const request = chunk.map((inflight) => inflight.request); + return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request)) + .then((result) => { + // For each result, feed it to the correct Promise, depending + // on whether it was a success or error + chunk.forEach((inflightRequest, index) => { + const payload = result[index]; + if (_optionalChain$1([payload, 'optionalAccess', _ => _.error])) { + const error = new Error(payload.error.message); + error.code = payload.error.code; + error.data = payload.error.data; + inflightRequest.reject(error); + } else if(_optionalChain$1([payload, 'optionalAccess', _2 => _2.result])) { + inflightRequest.resolve(payload.result); + } else { + inflightRequest.reject(); + } + }); + }).catch((error) => { + if(error && error.code == 'SERVER_ERROR') { + const index = this._endpoints.indexOf(this._endpoint)+1; + this._failover(); + this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; + this.requestChunk(chunk, this._endpoint); } else { - inflightRequest.reject(); + chunk.forEach((inflightRequest) => { + inflightRequest.reject(error); + }); } - }); - }).catch((error) => { - if(error && error.code == 'SERVER_ERROR') { - const index = this._endpoints.indexOf(this._endpoint)+1; - this._failover(); - this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; - this.requestChunk(chunk, this._endpoint); - } else { - chunk.forEach((inflightRequest) => { - inflightRequest.reject(error); - }); - } - }) + }) + + } catch (e) { + + chunk.forEach((inflightRequest) => { + inflightRequest.reject(); + }); + } } send(method, params) { diff --git a/dist/umd/index.js b/dist/umd/index.js index e624f65..2be5878 100644 --- a/dist/umd/index.js +++ b/dist/umd/index.js @@ -52,38 +52,46 @@ } requestChunk(chunk, endpoint) { - - const request = chunk.map((inflight) => inflight.request); - - return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request)) - .then((result) => { - // For each result, feed it to the correct Promise, depending - // on whether it was a success or error - chunk.forEach((inflightRequest, index) => { - const payload = result[index]; - if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { - const error = new Error(payload.error.message); - error.code = payload.error.code; - error.data = payload.error.data; - inflightRequest.reject(error); - } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { - inflightRequest.resolve(payload.result); + + try { + + const request = chunk.map((inflight) => inflight.request); + return ethers.ethers.utils.fetchJson(endpoint, JSON.stringify(request)) + .then((result) => { + // For each result, feed it to the correct Promise, depending + // on whether it was a success or error + chunk.forEach((inflightRequest, index) => { + const payload = result[index]; + if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) { + const error = new Error(payload.error.message); + error.code = payload.error.code; + error.data = payload.error.data; + inflightRequest.reject(error); + } else if(_optionalChain$3([payload, 'optionalAccess', _2 => _2.result])) { + inflightRequest.resolve(payload.result); + } else { + inflightRequest.reject(); + } + }); + }).catch((error) => { + if(error && error.code == 'SERVER_ERROR') { + const index = this._endpoints.indexOf(this._endpoint)+1; + this._failover(); + this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; + this.requestChunk(chunk, this._endpoint); } else { - inflightRequest.reject(); + chunk.forEach((inflightRequest) => { + inflightRequest.reject(error); + }); } - }); - }).catch((error) => { - if(error && error.code == 'SERVER_ERROR') { - const index = this._endpoints.indexOf(this._endpoint)+1; - this._failover(); - this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]; - this.requestChunk(chunk, this._endpoint); - } else { - chunk.forEach((inflightRequest) => { - inflightRequest.reject(error); - }); - } - }) + }) + + } catch (e) { + + chunk.forEach((inflightRequest) => { + inflightRequest.reject(); + }); + } } send(method, params) { diff --git a/package.evm.json b/package.evm.json index 123b402..c08c2ad 100644 --- a/package.evm.json +++ b/package.evm.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-evm", "moduleName": "Web3Client", - "version": "10.18.1", + "version": "10.18.2", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.evm.js", "module": "dist/esm/index.evm.js", diff --git a/package.json b/package.json index 54b4335..1461208 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client", "moduleName": "Web3Client", - "version": "10.18.1", + "version": "10.18.2", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.js", "module": "dist/esm/index.js", diff --git a/package.solana.json b/package.solana.json index a1c4c1a..7eae185 100644 --- a/package.solana.json +++ b/package.solana.json @@ -1,7 +1,7 @@ { "name": "@depay/web3-client-solana", "moduleName": "Web3Client", - "version": "10.18.1", + "version": "10.18.2", "description": "A web3 client to fetch blockchain data just like you are used to with HTTP clients.", "main": "dist/umd/index.solana.js", "module": "dist/esm/index.solana.js", diff --git a/src/clients/ethers/provider.js b/src/clients/ethers/provider.js index 742f66c..bd934a2 100644 --- a/src/clients/ethers/provider.js +++ b/src/clients/ethers/provider.js @@ -21,38 +21,46 @@ class StaticJsonRpcBatchProvider extends ethers.providers.JsonRpcProvider { } requestChunk(chunk, endpoint) { - - const request = chunk.map((inflight) => inflight.request) - - return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) - .then((result) => { - // For each result, feed it to the correct Promise, depending - // on whether it was a success or error - chunk.forEach((inflightRequest, index) => { - const payload = result[index] - if (payload?.error) { - const error = new Error(payload.error.message) - error.code = payload.error.code - error.data = payload.error.data - inflightRequest.reject(error) - } else if(payload?.result) { - inflightRequest.resolve(payload.result) + + try { + + const request = chunk.map((inflight) => inflight.request) + return ethers.utils.fetchJson(endpoint, JSON.stringify(request)) + .then((result) => { + // For each result, feed it to the correct Promise, depending + // on whether it was a success or error + chunk.forEach((inflightRequest, index) => { + const payload = result[index] + if (payload?.error) { + const error = new Error(payload.error.message) + error.code = payload.error.code + error.data = payload.error.data + inflightRequest.reject(error) + } else if(payload?.result) { + inflightRequest.resolve(payload.result) + } else { + inflightRequest.reject() + } + }) + }).catch((error) => { + if(error && error.code == 'SERVER_ERROR') { + const index = this._endpoints.indexOf(this._endpoint)+1 + this._failover() + this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index] + this.requestChunk(chunk, this._endpoint) } else { - inflightRequest.reject() + chunk.forEach((inflightRequest) => { + inflightRequest.reject(error) + }) } }) - }).catch((error) => { - if(error && error.code == 'SERVER_ERROR') { - const index = this._endpoints.indexOf(this._endpoint)+1 - this._failover() - this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index] - this.requestChunk(chunk, this._endpoint) - } else { - chunk.forEach((inflightRequest) => { - inflightRequest.reject(error) - }) - } + + } catch { + + chunk.forEach((inflightRequest) => { + inflightRequest.reject() }) + } } send(method, params) {