Skip to content

Commit a84187b

Browse files
committed
feat(staking): add error logging to useData
1 parent c39c85e commit a84187b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

apps/staking/src/hooks/use-data.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { useCallback } from "react";
22
import useSWR, { type KeyedMutator } from "swr";
33

4+
import { useLogger } from "./use-logger";
5+
46
export const useData = <T>(...args: Parameters<typeof useSWR<T>>) => {
57
const { data, isLoading, mutate, ...rest } = useSWR(...args);
68

79
const error = rest.error as unknown;
10+
const logger = useLogger();
811

912
const reset = useCallback(() => {
1013
mutate(undefined).catch(() => {
@@ -13,7 +16,8 @@ export const useData = <T>(...args: Parameters<typeof useSWR<T>>) => {
1316
}, [mutate]);
1417

1518
if (error) {
16-
return State.ErrorState(new LoadDashboardDataError(error), reset);
19+
logger.error(error);
20+
return State.ErrorState(new UseDataError(error), reset);
1721
} else if (isLoading) {
1822
return State.Loading();
1923
} else if (data) {
@@ -38,17 +42,17 @@ const State = {
3842
mutate,
3943
data,
4044
}),
41-
ErrorState: (error: LoadDashboardDataError, reset: () => void) => ({
45+
ErrorState: (error: UseDataError, reset: () => void) => ({
4246
type: StateType.Error as const,
4347
error,
4448
reset,
4549
}),
4650
};
4751

48-
class LoadDashboardDataError extends Error {
52+
class UseDataError extends Error {
4953
constructor(cause: unknown) {
5054
super(cause instanceof Error ? cause.message : "");
51-
this.name = "LoadDashboardDataError";
55+
this.name = "UseDataError";
5256
this.cause = cause;
5357
}
5458
}

0 commit comments

Comments
 (0)