diff --git a/src/api.ts b/src/api.ts index eaf9fd87..416cdf19 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 }) } @@ -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 + }) }) }) } @@ -3632,7 +3637,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])