next-recomponents 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,15 +3,14 @@ import { EnhancedEndpoints, ItemsRecord, Props, ShowOptions } from "./types";
3
3
  import useToken from "./get.token";
4
4
  import axios from "axios";
5
5
  import httpStatusCodes from "./http.codes";
6
- import { useRouter } from "next/navigation";
7
6
 
8
7
  export default function useResources<T extends Record<string, ItemsRecord>>({
9
8
  baseURI,
10
9
  authURI = "/auth/login",
11
10
  endpoints,
11
+ onError,
12
12
  }: Props) {
13
13
  const token = useToken();
14
- const router = useRouter();
15
14
  const [info, setInfo] = useState<Record<string, any>>({});
16
15
 
17
16
  const result = useMemo(() => {
@@ -61,7 +60,7 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
61
60
  newInfo[key].state = "error";
62
61
  newInfo[key].errorMessage = item?.meaning;
63
62
  if (error.status == 403) {
64
- router.push(authURI);
63
+ onError?.({ error, ...{ errorMessage: item?.meaning } });
65
64
  }
66
65
  setInfo({ ...newInfo });
67
66
  return error;
@@ -111,7 +110,7 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
111
110
  newInfo[key].state = "error";
112
111
  newInfo[key].errorMessage = item?.meaning || error.message;
113
112
  if (error.status == 403) {
114
- router.push(authURI);
113
+ onError?.({ error, ...{ errorMessage: item?.meaning } });
115
114
  }
116
115
  setInfo({ ...newInfo });
117
116
  return error;
@@ -150,14 +149,14 @@ export default function useResources<T extends Record<string, ItemsRecord>>({
150
149
  }
151
150
  }
152
151
  setInfo({ ...newInfo });
153
- return d.data;
152
+ return d;
154
153
  } catch (error: any) {
155
154
  const item = httpStatusCodes.find((s) => s.code == error.status);
156
155
 
157
156
  newInfo[key].state = "error";
158
157
  newInfo[key].errorMessage = item?.meaning || error.message;
159
158
  if (error.status == 403) {
160
- router.push(authURI);
159
+ onError?.({ error, ...{ errorMessage: item?.meaning } });
161
160
  }
162
161
  setInfo({ ...newInfo });
163
162
  return error;
@@ -6,6 +6,7 @@ export interface Props {
6
6
  baseURI: string;
7
7
  authURI?: string;
8
8
  endpoints: Record<string, Partial<ItemsRecord>>;
9
+ onError?: (error: any) => void;
9
10
  }
10
11
 
11
12
  export interface ShowOptions {