Skip to content

Commit dd72fea

Browse files
reuse AbortError
1 parent 19e4935 commit dd72fea

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

packages/client/lib/client/index.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ describe('Client', () => {
283283
});
284284

285285
testUtils.testWithClient('CommandTimeoutError', async client => {
286-
const promise = assert.rejects(client.sendCommand(['PING']), CommandTimeoutError),
287-
start = process.hrtime.bigint();
286+
const promise = assert.rejects(client.sendCommand(['PING']), AbortError);
287+
const start = process.hrtime.bigint();
288288

289289
while (process.hrtime.bigint() - start < 50_000_000) {
290-
// block the event loop for 1ms, to make sure the connection will timeout
290+
// block the event loop for 50ms, to make sure the connection will timeout
291291
}
292292

293293
await promise;

packages/client/lib/client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BasicAuth, CredentialsError, CredentialsProvider, StreamingCredentialsP
44
import RedisCommandsQueue, { CommandOptions } from './commands-queue';
55
import { EventEmitter } from 'node:events';
66
import { attachConfig, functionArgumentsPrefix, getTransformReply, scriptArgumentsPrefix } from '../commander';
7-
import { ClientClosedError, ClientOfflineError, CommandTimeoutError, DisconnectsClientError, WatchError } from '../errors';
7+
import { ClientClosedError, ClientOfflineError, AbortError, DisconnectsClientError, WatchError } from '../errors';
88
import { URL } from 'node:url';
99
import { TcpSocketConnectOpts } from 'node:net';
1010
import { PUBSUB_TYPE, PubSubType, PubSubListener, PubSubTypeListeners, ChannelListeners } from './pub-sub';
@@ -918,7 +918,7 @@ export default class RedisClient<
918918
return new Promise<T>((resolve, reject) => {
919919
const timeoutId = setTimeout(() => {
920920
controller.abort();
921-
reject(new CommandTimeoutError());
921+
reject(new AbortError());
922922
}, this._self.#options?.commandTimeout)
923923
promise.then(result => {
924924
clearInterval(timeoutId);

packages/client/lib/errors.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ export class SocketTimeoutError extends Error {
2222
}
2323
}
2424

25-
export class CommandTimeoutError extends Error {
26-
constructor() {
27-
super('Command timeout');
28-
}
29-
}
30-
3125
export class ClientClosedError extends Error {
3226
constructor() {
3327
super('The client is closed');

0 commit comments

Comments
 (0)