From 28b72064712a3d97b44511206a2dca07f2d37a23 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期四, 31 十月 2024 10:45:48 +0800
Subject: [PATCH] 描述

---
 src/utils/request.ts |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/utils/request.ts b/src/utils/request.ts
index 70eebb1..885b50e 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -1,15 +1,17 @@
-import type { AxiosInstance, AxiosRequestConfig } from 'axios';
+import type { AxiosInstance, AxiosRequestConfig, CancelToken } from 'axios';
 import axios from 'axios';
 import { ElLoadingService, ElMessage } from 'element-plus';
 import router from '../router';
-import { debounce } from './util';
+import { debounce, decodeFormData } from './util';
 import { AUTH_URL, MAIN_URL, SECONDARY_URL } from '/@/constants';
 import { Local, Session } from '/@/utils/storage';
+import { Logger } from '../model/logger/Logger';
 // import JSONbig from 'json-bigint';
 export type ExtraConfig = {
 	loading?: boolean;
 	noAuth?: boolean;
 	handleFail?: boolean;
+	cancelToken?: CancelToken | undefined;
 };
 export const checkAuth = () => {
 	const session = Local.get(accessSessionKey);
@@ -37,14 +39,15 @@
 	clearAccessTokens();
 	window.location.reload();
 });
+window.handleNoAuth = handleNoAuth;
 
 let requestNum = 0;
 let loadingInstance: ReturnType<typeof ElLoadingService>;
 const addLoading = () => {
-	// 澧炲姞loading 濡傛灉pending璇锋眰鏁伴噺绛変簬1锛屽脊鍑簂oading, 闃叉閲嶅寮瑰嚭
+	// 澧炲姞loading 濡傛灉pending璇锋眰鏁伴噺绛変簬1锛屽脊鍑簂oading, 闃叉閲嶅寮瑰嚭F
 	requestNum++;
 	if (requestNum == 1) {
-		 loadingInstance = ElLoadingService({
+		loadingInstance = ElLoadingService({
 			text: '鍔犺浇涓�...',
 			target: '.layout-parent',
 		});
@@ -72,7 +75,7 @@
 				config.headers['hswatersession'] = accessSession;
 			}
 			if (!noAuth) {
-				if (!accessSession ) {
+				if (!accessSession) {
 					handleNoAuth();
 				}
 			}
@@ -111,18 +114,23 @@
 				switch (serveData?.err_code) {
 					case ErrorCode.Auth:
 						handleNoAuth();
-							throw '鏉冮檺楠岃瘉澶辫触';
-						break;
+						throw '鏉冮檺楠岃瘉澶辫触';
 					case ErrorCode.Exception:
+						const param = res.config.data ? `\n    璇锋眰鍙傛暟锛�${JSON.stringify(decodeFormData(res.config.data))}\n` : '';
 						ElMessage.error('鍐呴儴閿欒锛�');
-						throw '鍐呴儴閿欒';
+						Logger.error(`${res.config.url} 鍝嶅簲澶辫触${param}`, serveData?.json_msg && new Error(serveData?.json_msg));
+						throw '';
+
+						return res.data;
 				}
 				// 闈� message error锛屼笖 handleFail 涓� true
 				// message error 涓嶉渶瑕佸鐞�
 				if (handleFail && serveData?.err_code !== ErrorCode.Message) {
-					const errorText = serveData?.json_msg || '鍝嶅簲澶辫触锛�';
+					const errorText = serveData?.json_msg;
 					ElMessage.error(errorText);
-					throw errorText;
+					const param = res.config.data ? `\n    璇锋眰鍙傛暟锛�${JSON.stringify(decodeFormData(res.config.data))}\n` : '';
+					Logger.error(`${res.config.url} 鍝嶅簲澶辫触${param}`, errorText && new Error(errorText));
+					throw '';
 				}
 			}
 			return res.data;

--
Gitblit v1.9.3