Skip to content

Commit

Permalink
fix(front): include response in custom fetch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Nov 7, 2023
1 parent f036362 commit 28f1d2e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/front/services/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
* @returns object
*/
export default async function myFetch(url, options, parseJson) {
class HTTPError extends Error {}
class HTTPError extends Error {
constructor(message, response) {
super(message);
this.name = 'HTTPError';
this.response = response;
}
}

const fetchOptions = { ...options };
if (options.json) {
Expand Down Expand Up @@ -41,6 +47,7 @@ export default async function myFetch(url, options, parseJson) {
}
throw new HTTPError(
`Fetch error: status code: ${response.status} text: ${errorText}`,
response,
);
}

Expand Down

0 comments on commit 28f1d2e

Please sign in to comment.