Skip to content

Commit

Permalink
v10.18.10: improve solana nested rpc response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNe0x1 committed Aug 16, 2024
1 parent 54cf78f commit edd7c0d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
16 changes: 11 additions & 5 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
if(attempt < MAX_RETRY) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new Connection(this._endpoint);
Expand Down Expand Up @@ -302,7 +300,15 @@ class StaticJsonRpcSequentialProvider extends Connection {
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson);
if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) {
if(attempt < MAX_RETRY) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
Expand All @@ -320,7 +326,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
.then((result) => {
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
Expand Down
16 changes: 11 additions & 5 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
if(attempt < MAX_RETRY) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new Connection(this._endpoint);
Expand Down Expand Up @@ -77,7 +75,15 @@ class StaticJsonRpcSequentialProvider extends Connection {
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson);
if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) {
if(attempt < MAX_RETRY) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
Expand All @@ -95,7 +101,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
.then((result) => {
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
Expand Down
16 changes: 11 additions & 5 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
if(attempt < MAX_RETRY) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new solanaWeb3_js.Connection(this._endpoint);
Expand Down Expand Up @@ -308,7 +306,15 @@
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson);
if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) {
if(attempt < MAX_RETRY) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
Expand All @@ -326,7 +332,7 @@
.then((result) => {
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
Expand Down
16 changes: 11 additions & 5 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
if(attempt < MAX_RETRY) {
const index = this._endpoints.indexOf(this._endpoint)+1;
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index];
this._provider = new solanaWeb3_js.Connection(this._endpoint);
Expand Down Expand Up @@ -83,7 +81,15 @@
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson);
if(parsedJson.find((entry)=>_optionalChain$3([entry, 'optionalAccess', _ => _.error]))) {
if(attempt < MAX_RETRY) {
reject('Error in batch found!');
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject);
} else {
reject(`${response.status} ${response.text}`);
Expand All @@ -101,7 +107,7 @@
.then((result) => {
chunk.forEach((inflightRequest, index) => {
const payload = result[index];
if (_optionalChain$3([payload, 'optionalAccess', _ => _.error])) {
if (_optionalChain$3([payload, 'optionalAccess', _2 => _2.error])) {
const error = new Error(payload.error.message);
error.code = payload.error.code;
error.data = payload.error.data;
Expand Down
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-evm",
"moduleName": "Web3Client",
"version": "10.18.9",
"version": "10.18.10",
"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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client",
"moduleName": "Web3Client",
"version": "10.18.9",
"version": "10.18.10",
"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",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-client-solana",
"moduleName": "Web3Client",
"version": "10.18.9",
"version": "10.18.10",
"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",
Expand Down
14 changes: 10 additions & 4 deletions src/clients/solana/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class StaticJsonRpcSequentialProvider extends Connection {
}

handleError(error, attempt, chunk) {
if(attempt < MAX_RETRY && error && [
'Failed to fetch', 'limit reached', '504', '503', '502', '500', '429', '426', '422', '413', '409', '408', '406', '405', '404', '403', '402', '401', '400'
].some((errorType)=>error.toString().match(errorType))) {
if(attempt < MAX_RETRY) {
const index = this._endpoints.indexOf(this._endpoint)+1
this._endpoint = index >= this._endpoints.length ? this._endpoints[0] : this._endpoints[index]
this._provider = new Connection(this._endpoint)
Expand Down Expand Up @@ -51,7 +49,15 @@ class StaticJsonRpcSequentialProvider extends Connection {
).then((response)=>{
if(response.ok) {
response.json().then((parsedJson)=>{
resolve(parsedJson)
if(parsedJson.find((entry)=>entry?.error)) {
if(attempt < MAX_RETRY) {
reject('Error in batch found!')
} else {
resolve(parsedJson);
}
} else {
resolve(parsedJson);
}
}).catch(reject)
} else {
reject(`${response.status} ${response.text}`)
Expand Down

0 comments on commit edd7c0d

Please sign in to comment.