Skip to content

Commit

Permalink
[CCI] Connection request method callback (opensearch-project#478)
Browse files Browse the repository at this point in the history
* fix: callback error required args

Signed-off-by: Timur Bolotov <bolotovtmr@gmail.com>
  • Loading branch information
timursaurus authored and AMoo-Miki committed Jul 12, 2023
1 parent bb34981 commit 9f09f33
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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

Expand Down
2 changes: 1 addition & 1 deletion lib/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export declare class ConnectionError<
name: string;
message: string;
meta: ApiResponse<TResponse, TContext>;
constructor(message: string, meta: ApiResponse);
constructor(message: string, meta?: ApiResponse);
}

export declare class NoLivingConnectionsError<
Expand Down Expand Up @@ -104,7 +104,7 @@ export declare class RequestAbortedError<
name: string;
message: string;
meta: ApiResponse<TResponse, TContext>;
constructor(message: string, meta: ApiResponse);
constructor(message: string, meta?: ApiResponse);
}

export declare class NotCompatibleError<
Expand Down
32 changes: 32 additions & 0 deletions test/unit/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

0 comments on commit 9f09f33

Please sign in to comment.