diff --git a/src/node.js b/src/node.js index 54933dda6a..0f50bad533 100644 --- a/src/node.js +++ b/src/node.js @@ -76,7 +76,15 @@ const Node = AsyncInit.compose({ if (!url) throw new Error('"url" required') this.url = url.replace(/\/$/, '') this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url - const client = await genSwaggerClient(`${this.url}/api?oas3`, { internalUrl: this.internalUrl }) + const client = await genSwaggerClient(`${this.url}/api?oas3`, { + internalUrl: this.internalUrl, + responseInterceptor: response => { + if (response.ok) return + return Object.assign(response, { + statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason + }) + } + }) this.version = client.spec.info.version if ( !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && diff --git a/test/integration/node.js b/test/integration/node.js index 34fdb65719..90d507ff48 100644 --- a/test/integration/node.js +++ b/test/integration/node.js @@ -51,6 +51,11 @@ describe('Node client', function () { ) }) + it('throws clear exceptions when can\'t get transaction by hash', async () => { + await expect(node.api.getTransactionByHash('th_test')) + .to.be.rejectedWith('v3/transactions/th_test error: Invalid hash') + }) + describe('Node Pool', () => { it('throw error on invalid node object', async () => { const nodes = await NodePool()