Skip to content

Commit

Permalink
Include response in error
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmaim committed Feb 21, 2024
1 parent cb0003c commit f2279b1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/fetch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ export function fetchGw2Api<
url.searchParams.set('access_token', options.accessToken);
}

return fetch(url).then((r) => {
return fetch(url, { redirect: 'manual' }).then((r) => {
if(!r.ok) {
throw new Error( `The GW2 API call to '${url.toString()}' returned ${r.status} ${r.statusText}.`);
throw new Gw2ApiError( `The GW2 API call to '${url.toString()}' returned ${r.status} ${r.statusText}.`, r);
}

// TODO: catch more errors

return r.json();
});
}

class Gw2ApiError extends Error {
constructor(message: string, public response: Response) {
super(message);
}
}

function hasLanguage(options: OptionsByEndpoint<any>): options is LocalizedOptions {
return 'language' in options;
}
Expand Down

0 comments on commit f2279b1

Please sign in to comment.