@lark-apaas/client-toolkit 1.2.35-alpha.3 → 1.2.35-alpha.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/lib/locales/messages.js +24 -0
- package/lib/utils/axiosConfig.js +10 -6
- package/package.json +1 -1
package/lib/locales/messages.js
CHANGED
|
@@ -102,6 +102,30 @@ const messages_messages = {
|
|
|
102
102
|
'userProfile.label.email': {
|
|
103
103
|
zh: '邮箱',
|
|
104
104
|
en: 'Email'
|
|
105
|
+
},
|
|
106
|
+
'axios.log.requestSuccess': {
|
|
107
|
+
zh: '请求成功:',
|
|
108
|
+
en: 'Request succeeded: '
|
|
109
|
+
},
|
|
110
|
+
'axios.log.requestFailed': {
|
|
111
|
+
zh: '请求失败:',
|
|
112
|
+
en: 'Request failed: '
|
|
113
|
+
},
|
|
114
|
+
'axios.log.networkFailed': {
|
|
115
|
+
zh: '网络请求失败:',
|
|
116
|
+
en: 'Network request failed: '
|
|
117
|
+
},
|
|
118
|
+
'axios.log.noResponseOrConfig': {
|
|
119
|
+
zh: '请求失败:无响应对象或配置信息',
|
|
120
|
+
en: 'Request failed: no response object or config'
|
|
121
|
+
},
|
|
122
|
+
'axios.log.forbidden': {
|
|
123
|
+
zh: '请求被拒绝(403):{method} {url}',
|
|
124
|
+
en: 'Request rejected (403): {method} {url}'
|
|
125
|
+
},
|
|
126
|
+
'axios.log.unknownError': {
|
|
127
|
+
zh: '未知错误',
|
|
128
|
+
en: 'Unknown error'
|
|
105
129
|
}
|
|
106
130
|
};
|
|
107
131
|
const messages = messages_messages;
|
package/lib/utils/axiosConfig.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getStacktrace } from "../logger/selected-logs.js";
|
|
|
5
5
|
import { safeStringify } from "./safeStringify.js";
|
|
6
6
|
import { slardar } from "@lark-apaas/internal-slardar";
|
|
7
7
|
import { normalizeBasePath } from "./utils.js";
|
|
8
|
+
import { t } from "../locales/index.js";
|
|
8
9
|
const APP_CLIENT_API_LOG_TYPE = 'app_client_api_log';
|
|
9
10
|
function stripBasePath(urlPath) {
|
|
10
11
|
const base = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
|
@@ -95,8 +96,8 @@ async function logResponse(ok, responseOrError) {
|
|
|
95
96
|
if (isValidResponse(responseOrError)) {
|
|
96
97
|
const response = responseOrError;
|
|
97
98
|
const okToTextMap = {
|
|
98
|
-
success: '
|
|
99
|
-
error: '
|
|
99
|
+
success: t('axios.log.requestSuccess'),
|
|
100
|
+
error: t('axios.log.requestFailed')
|
|
100
101
|
};
|
|
101
102
|
const realOK = 'success' === ok && response.status >= 200 && response.status < 300;
|
|
102
103
|
const method = (response.config.method || 'GET').toUpperCase();
|
|
@@ -154,13 +155,13 @@ async function logResponse(ok, responseOrError) {
|
|
|
154
155
|
const error = responseOrError;
|
|
155
156
|
if (error && error.config && 'object' == typeof error.config) {
|
|
156
157
|
const errorType = error.code || 'UNKNOWN_ERROR';
|
|
157
|
-
const errorMessage = error.message || '
|
|
158
|
+
const errorMessage = error.message || t('axios.log.unknownError');
|
|
158
159
|
const method = (error.config.method || 'GET').toUpperCase();
|
|
159
160
|
const url = error.config.url || '';
|
|
160
161
|
const startTime = error.config._startTime;
|
|
161
162
|
const duration = startTime ? Date.now() - startTime : 0;
|
|
162
163
|
const parts = [
|
|
163
|
-
'
|
|
164
|
+
t('axios.log.networkFailed'),
|
|
164
165
|
method,
|
|
165
166
|
' ',
|
|
166
167
|
url.split('?')[0].replace(/^\/spark\/p\/app_\w+/, ''),
|
|
@@ -210,7 +211,7 @@ async function logResponse(ok, responseOrError) {
|
|
|
210
211
|
logger.log({
|
|
211
212
|
level: 'error',
|
|
212
213
|
args: [
|
|
213
|
-
'
|
|
214
|
+
t('axios.log.noResponseOrConfig')
|
|
214
215
|
],
|
|
215
216
|
meta: {}
|
|
216
217
|
});
|
|
@@ -360,7 +361,10 @@ function initAxiosConfig(axiosInstance) {
|
|
|
360
361
|
logger.log({
|
|
361
362
|
level: 'warn',
|
|
362
363
|
args: [
|
|
363
|
-
|
|
364
|
+
t('axios.log.forbidden', {
|
|
365
|
+
method,
|
|
366
|
+
url
|
|
367
|
+
}),
|
|
364
368
|
{
|
|
365
369
|
状态码: 403,
|
|
366
370
|
返回数据: error.response.data
|