From 9c545a477cf5e6e9ecf8f171af3857fd64b5a78d Mon Sep 17 00:00:00 2001 From: enes Date: Wed, 11 Sep 2024 16:33:53 +0200 Subject: [PATCH] fix(errors): add custom timeout error --- src/types/errors/TimeoutError.ts | 6 ++++++ src/utils/utils.ts | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 src/types/errors/TimeoutError.ts diff --git a/src/types/errors/TimeoutError.ts b/src/types/errors/TimeoutError.ts new file mode 100644 index 0000000..5bd31c5 --- /dev/null +++ b/src/types/errors/TimeoutError.ts @@ -0,0 +1,6 @@ +export class TimeoutError extends Error { + constructor() { + super('Timeout') + this.name = this.constructor.name + } +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index f32e14e..ee21230 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,3 +1,4 @@ +import { TimeoutError } from '../types/errors/TimeoutError.ts' import { CurrentUserFile } from '../types/file.ts' import { SigitFile } from './file.ts' @@ -63,7 +64,7 @@ export const timeout = (ms: number = 60000) => { // Set a timeout using setTimeout setTimeout(() => { // Reject the promise with an Error indicating a timeout - reject(new Error('Timeout')) + reject(new TimeoutError()) }, ms) // Timeout duration in milliseconds }) }