diff --git a/packages/errors/src/TankerError.ts b/packages/errors/src/TankerError.ts index d1b7a7d1..09825f47 100644 --- a/packages/errors/src/TankerError.ts +++ b/packages/errors/src/TankerError.ts @@ -6,6 +6,7 @@ export class TankerError extends Error { declare apiMethod?: string; declare apiRoute?: string; declare httpStatus?: number; + declare next?: Error; declare traceId?: string; constructor(name: string = 'TankerError', errorInfo?: ErrorInfo) { diff --git a/packages/errors/src/errors/DecryptionFailed.ts b/packages/errors/src/errors/DecryptionFailed.ts index ca50dec9..8d19ae8b 100644 --- a/packages/errors/src/errors/DecryptionFailed.ts +++ b/packages/errors/src/errors/DecryptionFailed.ts @@ -3,8 +3,6 @@ import { TankerError } from '../TankerError'; export class DecryptionFailed extends TankerError { b64ResourceId?: string; - next?: Error; - constructor(args: { error?: Error; message?: string; b64ResourceId?: string; }) { const { error, b64ResourceId } = args; let message = args.message; diff --git a/packages/errors/src/errors/NetworkError.ts b/packages/errors/src/errors/NetworkError.ts index 84d446e5..3440c04a 100644 --- a/packages/errors/src/errors/NetworkError.ts +++ b/packages/errors/src/errors/NetworkError.ts @@ -2,10 +2,12 @@ import type { ErrorInfo } from '../ErrorInfo'; import { TankerError } from '../TankerError'; export class NetworkError extends TankerError { - constructor(errorInfo?: ErrorInfo) { + constructor(errorInfo?: ErrorInfo, next?: Error) { super('NetworkError', errorInfo || 'Network error'); // Set the prototype explicitly. Object.setPrototypeOf(this, NetworkError.prototype); + + this.next = next; } } diff --git a/packages/http-utils/src/fetch.ts b/packages/http-utils/src/fetch.ts index 40eb2fa4..523894f5 100644 --- a/packages/http-utils/src/fetch.ts +++ b/packages/http-utils/src/fetch.ts @@ -13,7 +13,7 @@ if (globalThis.fetch && globalThis.Promise) { } const fetch = (input: RequestInfo, init?: RequestInit): Promise => baseFetch(input, { ...init, referrerPolicy: 'no-referrer' }).catch((err: Error) => { - throw new NetworkError(err.toString()); + throw new NetworkError(err.toString(), err); }); export { fetch };