diff --git a/packages/shared/common/src/errors.ts b/packages/shared/common/src/errors.ts index 600d0f03e8..f85a2cc92d 100644 --- a/packages/shared/common/src/errors.ts +++ b/packages/shared/common/src/errors.ts @@ -43,6 +43,13 @@ export class LDClientError extends Error { } } +export class LDTimeoutError extends Error { + constructor(message: string) { + super(message); + this.name = 'LaunchDarklyTimeoutError'; + } +} + /** * Check if the HTTP error is recoverable. This will return false if a request * made with any payload could not recover. If the reason for the failure diff --git a/packages/shared/common/src/utils/timedPromise.ts b/packages/shared/common/src/utils/timedPromise.ts index 420bf95516..790f230cf5 100644 --- a/packages/shared/common/src/utils/timedPromise.ts +++ b/packages/shared/common/src/utils/timedPromise.ts @@ -1,3 +1,5 @@ +import { LDTimeoutError } from '../errors'; + /** * Returns a promise which errors after t seconds. * @@ -8,7 +10,7 @@ const timedPromise = (t: number, taskName: string) => new Promise((_res, reject) => { setTimeout(() => { const e = `${taskName} timed out after ${t} seconds.`; - reject(new Error(e)); + reject(new LDTimeoutError(e)); }, t * 1000); });