From 81321c59dbc05731b6eaf21fc5565756b8690c90 Mon Sep 17 00:00:00 2001 From: CombatPug Date: Thu, 2 May 2024 12:20:14 +0100 Subject: [PATCH 1/2] feat: change rotation handling to status instead of message --- src/api.ts | 8 ++++---- src/utils.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api.ts b/src/api.ts index eaf9fd87..579e88f3 100755 --- a/src/api.ts +++ b/src/api.ts @@ -514,8 +514,8 @@ async function injectWithRetries(txHash: string, tx: any, args: any, retries = c result = await injectAndRecordTx(txHash, tx, args) if (result.success) { return result - } else if (result.reason === 'Node is too close to rotation edges. Inject to another node') { - console.log('Node is close to rotation edges. Rotating node...') + } else if (result.status === 503) { + if (result?.reason) console.log(result.reason) if (result.nodeUrl) { const urlParts = result.nodeUrl.split(':') removeFromNodeList(urlParts[0], urlParts[1]) @@ -651,7 +651,7 @@ async function injectAndRecordTx( nodeUrl: baseUrl, success: injectResult ? injectResult.success : false, reason: injectResult.reason, - status: injectResult.status, + status: injectResult.status ?? response.status }) } @@ -3632,7 +3632,7 @@ export const methods = { countFailedResponse(api_name, 'Invalid address') return } - + if (!isValidAddress(callObj.from)) { if (verbose) console.log('Invalid params: `from` is not valid address', callObj.from) callback({ code: -32000, message: 'Invalid params: `from` is not valid address' }, null) diff --git a/src/utils.ts b/src/utils.ts index 8963facb..fa41be19 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -282,8 +282,8 @@ export async function requestWithRetry( if (typeof res.data === 'object') res.data.nodeUrl = nodeUrl return res //break } - } else if (res.data.error === 'node close to rotation edges') { - console.log(`${nodeUrl} Node is close to rotation edges. Changing node...`) + } else if (res.status === 503) { + if (res.data.error) console.log(`${nodeUrl} ${res.data.error}`) if (nodeIpPort) { const urlParts = nodeIpPort.split(':') removeFromNodeList(urlParts[0], urlParts[1]) From dbb56f99dba061edebf4cba01764859b187c57cf Mon Sep 17 00:00:00 2001 From: CombatPug Date: Thu, 2 May 2024 13:36:54 +0100 Subject: [PATCH 2/2] fix: error handling for inject response --- src/api.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api.ts b/src/api.ts index 579e88f3..416cdf19 100755 --- a/src/api.ts +++ b/src/api.ts @@ -651,7 +651,7 @@ async function injectAndRecordTx( nodeUrl: baseUrl, success: injectResult ? injectResult.success : false, reason: injectResult.reason, - status: injectResult.status ?? response.status + status: injectResult.status }) } @@ -670,7 +670,7 @@ async function injectAndRecordTx( nodeUrl: baseUrl, success: injectResult ? injectResult.success : false, reason: injectResult.reason, - status: injectResult.status, + status: injectResult.status }) } else { countInjectTxRejections('No injection result') @@ -687,9 +687,9 @@ async function injectAndRecordTx( reject({ nodeUrl: baseUrl, error: 'Unable inject transaction to the network' }) } }) - .catch((e: Error) => { - if (config.verbose) console.log('injectAndRecordTx: Caught Exception: ' + e.message) - countInjectTxRejections('Caught Exception: ' + trimInjectRejection(e.message)) + .catch((error) => { + if (config.verbose) console.log('injectAndRecordTx: Caught Exception: ' + error?.message) + countInjectTxRejections('Caught Exception: ' + trimInjectRejection(error?.message)) if (config.recordTxStatus) recordTxStatus({ @@ -702,7 +702,12 @@ async function injectAndRecordTx( ip: args[1000], // this index slot is reserved for ip, check injectIP middleware l nodeUrl: baseUrl, }) - reject({ nodeUrl: baseUrl, error: 'Unable inject transaction to the network' }) + resolve({ + nodeUrl: baseUrl, + reason: error.response?.data?.reason ?? 'Unable inject transaction to the network', + status: error.response?.status, + success: false + }) }) }) }