From 9d5992bdf37482fc35440603e477966b11df5ef4 Mon Sep 17 00:00:00 2001 From: devjoaov Date: Wed, 26 Jun 2024 14:57:29 -0300 Subject: [PATCH] chore: add response error to useswr fetcher --- src/components/DataTable/useSWRDataTable.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/DataTable/useSWRDataTable.tsx b/src/components/DataTable/useSWRDataTable.tsx index 38a58f9..ecad715 100644 --- a/src/components/DataTable/useSWRDataTable.tsx +++ b/src/components/DataTable/useSWRDataTable.tsx @@ -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); @@ -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(); };