Skip to content

Commit

Permalink
Merge branch 'quentin/networkErrorNext' into 'master'
Browse files Browse the repository at this point in the history
Quentin/network error next

See merge request TankerHQ/sdk-js!988
  • Loading branch information
quentinvernot committed Oct 9, 2023
2 parents 0d8cfd5 + e060e2e commit 15ce4e8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/errors/src/TankerError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions packages/errors/src/errors/DecryptionFailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/errors/src/errors/NetworkError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion packages/http-utils/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (globalThis.fetch && globalThis.Promise) {
}

const fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => baseFetch(input, { ...init, referrerPolicy: 'no-referrer' }).catch((err: Error) => {
throw new NetworkError(err.toString());
throw new NetworkError(err.toString(), err);
});

export { fetch };

0 comments on commit 15ce4e8

Please sign in to comment.