Skip to content

Commit

Permalink
Merge pull request #85 from bleu/joao/click-1003-expirar-login-dos-us…
Browse files Browse the repository at this point in the history
…uarios-apos-4-dias

chore: add response error to useswr fetcher
  • Loading branch information
devjoaov authored Jul 1, 2024
2 parents e99e0d3 + 9d5992b commit 55235f3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/DataTable/useSWRDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ function formatRequestParams(originalObj) {
};
}

class FetchError extends Error {
response: Response;

constructor(message: string, response: Response) {
super(message);
this.response = response;
}
}

const dataTableFetcher = async ([pathOrUrl, paramsObject]) => {
const formattedParams = formatRequestParams(paramsObject);

Expand All @@ -25,7 +34,7 @@ const dataTableFetcher = async ([pathOrUrl, paramsObject]) => {
},
});
if (!response.ok) {
throw new Error("Failed to fetch.");
throw new FetchError("Failed to fetch", response);
}
return response.json();
};
Expand Down

0 comments on commit 55235f3

Please sign in to comment.