Skip to content

Commit

Permalink
feat(errors): expose rethrown error in NetworkError when relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinvernot committed Oct 9, 2023
1 parent 1680e9e commit e060e2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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 e060e2e

Please sign in to comment.