From 7d0aaf57ba3b4afb2714607063b39c38644841fd Mon Sep 17 00:00:00 2001 From: Timur Bolotov Date: Thu, 6 Apr 2023 23:30:10 +0600 Subject: [PATCH 1/3] fix: callback error required args Signed-off-by: Timur Bolotov --- lib/Connection.js | 2 +- lib/errors.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index bd71d2c53..680b94026 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -134,7 +134,7 @@ class Connection { request.once('error', () => {}); // we need to catch the request aborted error debug('Request aborted', params); this._openRequests--; - callback(new RequestAbortedError(), null); + callback(new RequestAbortedError('Request aborted'), null); }; request.on('response', onResponse); diff --git a/lib/errors.d.ts b/lib/errors.d.ts index 659975167..a907f5110 100644 --- a/lib/errors.d.ts +++ b/lib/errors.d.ts @@ -51,7 +51,7 @@ export declare class ConnectionError< name: string; message: string; meta: ApiResponse; - constructor(message: string, meta: ApiResponse); + constructor(message: string, meta?: ApiResponse); } export declare class NoLivingConnectionsError< @@ -104,7 +104,7 @@ export declare class RequestAbortedError< name: string; message: string; meta: ApiResponse; - constructor(message: string, meta: ApiResponse); + constructor(message: string, meta?: ApiResponse); } export declare class NotCompatibleError< From f7358200d15c4c0405359eab9ee4731150952bfd Mon Sep 17 00:00:00 2001 From: Timur Bolotov Date: Thu, 6 Apr 2023 23:37:26 +0600 Subject: [PATCH 2/3] feat: connection abort message test Signed-off-by: Timur Bolotov --- test/unit/connection.test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index d9f0268db..3724de112 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -1116,3 +1116,35 @@ test('Abort with a slow body', (t) => { setImmediate(() => request.abort()); }); + +test('Abort with message', (t) => { + t.plan(2); + + const connection = new Connection({ + url: new URL('https://localhost:9200'), + proxy: 'http://localhost:8080', + }); + + const slowBody = new Readable({ + read() { + setTimeout(() => { + this.push('{"size":1, "query":{"match_all":{}}}'); + this.push(null); // EOF + }, 1000).unref(); + }, + }); + + const request = connection.request( + { + method: 'GET', + path: '/', + body: slowBody, + }, + (err) => { + t.ok(err instanceof RequestAbortedError); + t.equal(err.message, 'Request aborted'); + } + ); + + setImmediate(() => request.abort()); +}); From 2f3e6a0dce96d09b00d5cf076350e8fa693f0980 Mon Sep 17 00:00:00 2001 From: Timur Bolotov Date: Thu, 6 Apr 2023 23:46:30 +0600 Subject: [PATCH 3/3] chore: update changelog Signed-off-by: Timur Bolotov --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eac4e4bac..9f17823b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,6 +94,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Changed - Remove test artifacts from gh_pages workflow ([#335](https://github.com/opensearch-project/opensearch-js/issues/335)) +- Make `TimeoutError` and `RequestAbortedError` classes' `meta` argument optional ([#478](https://github.com/opensearch-project/opensearch-js/pull/478/)) ### Deprecated