Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve error message for request errors #199

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export class FetchError<T = any> extends Error {

export function createFetchError<T = any> (request: FetchRequest, error?: Error, response?: FetchResponse<T>): FetchError<T> {
let message = "";
if (request && response) {
message = `${response.status} ${response.statusText} (${request.toString()})`;
}
if (error) {
message = `${error.message} (${message})`;
message = error.message;
}
if (request && response) {
message = `${message} (${response.status} ${response.statusText} (${request.toString()}))`;
} else if (request) {
message = `${message} (${request.toString()})`;
}

const fetchError: FetchError<T> = new FetchError(message);
Expand Down