@steroidsjs/core 2.2.59 → 2.2.60

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.
@@ -1,3 +1,4 @@
1
+ import { AxiosError } from 'axios';
1
2
  import { IComponents } from '../providers/ComponentsProvider';
2
3
  import { IApiMethod } from '../components/ApiComponent';
3
4
  declare global {
@@ -22,6 +23,7 @@ export interface IFetchResult {
22
23
  } | any;
23
24
  isLoading: boolean;
24
25
  fetch?: (newParams?: Record<string, unknown>) => void;
26
+ axiosError: AxiosError | null;
25
27
  }
26
28
  export declare const normalizeConfig: (config: any) => any;
27
29
  export declare const getConfigId: (config: any) => any;
package/hooks/useFetch.js CHANGED
@@ -111,7 +111,8 @@ function useFetch(rawConfig) {
111
111
  var preloadedDataByConfigId = (preloadedData && configId) ? preloadedData[configId] : null;
112
112
  // State for data and loading flag
113
113
  var _b = react_1.useState(preloadedDataByConfigId || null), data = _b[0], setData = _b[1];
114
- var _c = react_1.useState(!!config && !data), isLoading = _c[0], setIsLoading = _c[1];
114
+ var _c = react_1.useState(null), axiosError = _c[0], setAxiosError = _c[1];
115
+ var _d = react_1.useState(!!config && !data), isLoading = _d[0], setIsLoading = _d[1];
115
116
  // Cancel tokens
116
117
  var cancelTokens = react_1.useRef([]);
117
118
  var addCancelToken = function (token) { return cancelTokens.current.push(token); };
@@ -120,7 +121,7 @@ function useFetch(rawConfig) {
120
121
  var fetch = react_1.useCallback(function (newConfig) {
121
122
  if (newConfig === void 0) { newConfig = null; }
122
123
  return __awaiter(_this, void 0, void 0, function () {
123
- var _a;
124
+ var _a, error_1;
124
125
  return __generator(this, function (_b) {
125
126
  switch (_b.label) {
126
127
  case 0:
@@ -128,15 +129,26 @@ function useFetch(rawConfig) {
128
129
  setConfig(__assign(__assign(__assign({}, config), newConfig), { params: __assign(__assign({}, config === null || config === void 0 ? void 0 : config.params), newConfig === null || newConfig === void 0 ? void 0 : newConfig.params) }));
129
130
  }
130
131
  setData(null);
131
- if (!config) return [3 /*break*/, 2];
132
+ if (!config) return [3 /*break*/, 5];
132
133
  setIsLoading(true);
134
+ _b.label = 1;
135
+ case 1:
136
+ _b.trys.push([1, 3, , 4]);
133
137
  _a = setData;
134
138
  return [4 /*yield*/, exports.fetchData(config, components, addCancelToken)];
135
- case 1:
139
+ case 2:
136
140
  _a.apply(void 0, [_b.sent()]);
141
+ return [3 /*break*/, 4];
142
+ case 3:
143
+ error_1 = _b.sent();
144
+ if (error_1.isAxiosError) {
145
+ setAxiosError(error_1);
146
+ }
147
+ return [3 /*break*/, 4];
148
+ case 4:
137
149
  setIsLoading(false);
138
- _b.label = 2;
139
- case 2: return [2 /*return*/];
150
+ _b.label = 5;
151
+ case 5: return [2 /*return*/];
140
152
  }
141
153
  });
142
154
  });
@@ -150,6 +162,6 @@ function useFetch(rawConfig) {
150
162
  react_use_1.useUpdateEffect(function () {
151
163
  fetch();
152
164
  }, [fetch]);
153
- return { data: data, isLoading: isLoading, fetch: fetch };
165
+ return { data: data, isLoading: isLoading, fetch: fetch, axiosError: axiosError };
154
166
  }
155
167
  exports["default"] = useFetch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steroidsjs/core",
3
- "version": "2.2.59",
3
+ "version": "2.2.60",
4
4
  "description": "",
5
5
  "author": "Vladimir Kozhin <hello@kozhindev.com>",
6
6
  "repository": {