react-toolkits 2.13.7 → 2.13.9
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/CHANGELOG.md +12 -0
- package/lib/index.js +69 -68
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/index.js
CHANGED
|
@@ -281,85 +281,85 @@ var init_Interceptors = __esm({
|
|
|
281
281
|
getGameId,
|
|
282
282
|
permissionVersion
|
|
283
283
|
} = useToolkitsStore((s) => s);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
284
|
+
let requestInterceptorId;
|
|
285
|
+
let responseInterceptorId;
|
|
286
|
+
if (interceptors?.request) {
|
|
287
|
+
requestInterceptorId = axios2.interceptors.request.use(...interceptors.request);
|
|
288
|
+
} else {
|
|
289
|
+
requestInterceptorId = axios2.interceptors.request.use((config) => {
|
|
290
|
+
const headers = new AxiosHeaders(config.headers);
|
|
291
|
+
config.responseType = config.responseType || "json";
|
|
292
|
+
if (token) {
|
|
293
|
+
headers.setAuthorization(`Bearer ${token}`);
|
|
294
|
+
}
|
|
295
|
+
if (!headers.has(APP_ID_HEADER) && permissionVersion !== "v1" /* V1 */) {
|
|
296
|
+
const gameId = getGameId();
|
|
297
|
+
if (isGlobal || !gameId) {
|
|
298
|
+
headers.set(APP_ID_HEADER, "global");
|
|
299
|
+
} else {
|
|
300
|
+
headers.set(APP_ID_HEADER, gameId);
|
|
295
301
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
302
|
+
}
|
|
303
|
+
headers.set("Accept", config.responseType === "blob" ? "application/octet-stream" : "application/json");
|
|
304
|
+
config.headers = headers;
|
|
305
|
+
return config;
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
if (interceptors?.response) {
|
|
309
|
+
responseInterceptorId = axios2.interceptors.response.use(...interceptors.response);
|
|
310
|
+
} else {
|
|
311
|
+
responseInterceptorId = axios2.interceptors.response.use(
|
|
312
|
+
(response) => {
|
|
313
|
+
const responseType = response.request.responseType || "json";
|
|
314
|
+
if (responseType === "json") {
|
|
315
|
+
const data = response.data;
|
|
316
|
+
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
317
|
+
return response;
|
|
300
318
|
} else {
|
|
301
|
-
|
|
319
|
+
notification.error({
|
|
320
|
+
message: "Request failed",
|
|
321
|
+
description: data.msg
|
|
322
|
+
});
|
|
323
|
+
throw new Error(data.msg);
|
|
302
324
|
}
|
|
303
325
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
} else {
|
|
312
|
-
responseInterceptorId = axios2.interceptors.response.use(
|
|
313
|
-
(response) => {
|
|
314
|
-
const responseType = response.request.responseType || "json";
|
|
315
|
-
if (responseType === "json") {
|
|
316
|
-
const data = response.data;
|
|
317
|
-
if (data.code === 0 || data.code === 200 || data.status === 0 || data.errno === 0) {
|
|
318
|
-
return response;
|
|
319
|
-
} else {
|
|
320
|
-
notification.error({
|
|
321
|
-
message: "Request failed",
|
|
322
|
-
description: data.msg
|
|
323
|
-
});
|
|
324
|
-
throw new Error(data.msg);
|
|
325
|
-
}
|
|
326
|
+
return response;
|
|
327
|
+
},
|
|
328
|
+
(error) => {
|
|
329
|
+
if (isAxiosError(error)) {
|
|
330
|
+
const response = error.response;
|
|
331
|
+
if (!response) {
|
|
332
|
+
throw error;
|
|
326
333
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const response = error.response;
|
|
332
|
-
if (!response) {
|
|
333
|
-
throw error;
|
|
334
|
-
}
|
|
335
|
-
if (response.status === 401 || response.status === 412) {
|
|
336
|
-
clearToken();
|
|
337
|
-
if (response.status === 412) {
|
|
338
|
-
setUnregistered();
|
|
339
|
-
}
|
|
340
|
-
window.location.replace(signInPath);
|
|
341
|
-
} else if (response.status === 403) {
|
|
342
|
-
notification.error({
|
|
343
|
-
message: "Forbidden",
|
|
344
|
-
description: "You do not have permission to access this resource."
|
|
345
|
-
});
|
|
346
|
-
} else {
|
|
347
|
-
notification.error({
|
|
348
|
-
message: "Request failed",
|
|
349
|
-
description: response.data.msg
|
|
350
|
-
});
|
|
351
|
-
throw new Error(response.data.msg);
|
|
334
|
+
if (response.status === 401 || response.status === 412) {
|
|
335
|
+
clearToken?.();
|
|
336
|
+
if (response.status === 412) {
|
|
337
|
+
setUnregistered();
|
|
352
338
|
}
|
|
339
|
+
window.location.replace(signInPath);
|
|
340
|
+
} else if (response.status === 403) {
|
|
341
|
+
notification.error({
|
|
342
|
+
message: "Forbidden",
|
|
343
|
+
description: "You do not have permission to access this resource."
|
|
344
|
+
});
|
|
345
|
+
} else {
|
|
346
|
+
notification.error({
|
|
347
|
+
message: "Request failed",
|
|
348
|
+
description: response.data.msg
|
|
349
|
+
});
|
|
350
|
+
throw new Error(response.data.msg);
|
|
353
351
|
}
|
|
354
|
-
throw error;
|
|
355
352
|
}
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
useEffect(() => {
|
|
358
358
|
return () => {
|
|
359
359
|
axios2.interceptors.request.eject(requestInterceptorId);
|
|
360
360
|
axios2.interceptors.response.eject(responseInterceptorId);
|
|
361
361
|
};
|
|
362
|
-
}, [
|
|
362
|
+
}, []);
|
|
363
363
|
return children;
|
|
364
364
|
};
|
|
365
365
|
Interceptors_default = Interceptors;
|
|
@@ -540,7 +540,8 @@ var init_hooks2 = __esm({
|
|
|
540
540
|
const { data, ...rest } = useSWR5(
|
|
541
541
|
codes.length ? [
|
|
542
542
|
permissionVersion !== "v1" /* V1 */ ? "/api/usystem/user/checkV2" : "/api/usystem/user/check",
|
|
543
|
-
{ permissions: codes }
|
|
543
|
+
{ permissions: codes },
|
|
544
|
+
config
|
|
544
545
|
] : null,
|
|
545
546
|
([url4, body]) => axios2.post(url4, body, config).then((response) => response.data.data)
|
|
546
547
|
);
|