@tmsfe/tms-core 0.0.200 → 0.0.202
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 +1 -1
- package/src/report/helper.ts +2 -2
- package/src/request.js +20 -2
package/package.json
CHANGED
package/src/report/helper.ts
CHANGED
|
@@ -44,8 +44,8 @@ function getSystemInfo(): ISystemInfo {
|
|
|
44
44
|
if (!systemInfo) {
|
|
45
45
|
const currentSystemInfo = wx.getSystemInfoSync() as any;
|
|
46
46
|
// eslint-disable-next-line
|
|
47
|
-
const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host
|
|
48
|
-
systemInfo = { model, wxVersion, platform, SDKVersion, host
|
|
47
|
+
const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host } = currentSystemInfo;
|
|
48
|
+
systemInfo = { model, wxVersion, platform, SDKVersion, host };
|
|
49
49
|
}
|
|
50
50
|
return systemInfo;
|
|
51
51
|
}
|
package/src/request.js
CHANGED
|
@@ -407,7 +407,7 @@ export default class Request {
|
|
|
407
407
|
const res = await this.invokeRequest(path, param, method, header);
|
|
408
408
|
// format 业务errcode,用于判断是否做重试
|
|
409
409
|
const { errCode } = formatResErrCode(path, res.data);
|
|
410
|
-
//
|
|
410
|
+
// 重试case1:处理token失效情况(errcode=35)
|
|
411
411
|
const needRetryLogin = errCode === 35 && isPathNeedRetryLogin(path);
|
|
412
412
|
if (needRetryLogin) {
|
|
413
413
|
// 调用runtime的login方法刷新token
|
|
@@ -415,9 +415,24 @@ export default class Request {
|
|
|
415
415
|
// 刷新后重试一次请求
|
|
416
416
|
return await this.invokeRequest(path, param, method, header);
|
|
417
417
|
}
|
|
418
|
+
|
|
419
|
+
// 重试case3:处理网关框架码重试 requestRetryFlag?.gatewayCode由七彩石配置
|
|
420
|
+
const { requestRetryFlag } = wx.tmsFlagMap || {};
|
|
421
|
+
// X-Gateway-Code必须首字母大写,否则真机取不到
|
|
422
|
+
const gatewayCode = res?.header?.['X-Gateway-Code'];
|
|
423
|
+
if (requestRetryFlag?.gatewayCode && isGatewayCodeNeedRetry(gatewayCode)) {
|
|
424
|
+
return await this.handleReTry(path, param, method, header, {
|
|
425
|
+
reportMsg: {
|
|
426
|
+
gatewayCode,
|
|
427
|
+
errMsg: `home gateway code ${gatewayCode} requires retry`,
|
|
428
|
+
},
|
|
429
|
+
waitTime: 10, // 网关框架码错误10ms后再重试
|
|
430
|
+
isSuccess: retryRes => !isGatewayCodeNeedRetry(retryRes?.header?.gatewayCode),
|
|
431
|
+
});
|
|
432
|
+
}
|
|
418
433
|
return res;
|
|
419
434
|
} catch (err) {
|
|
420
|
-
//
|
|
435
|
+
// 重试case2:微信系统errno:在重试码白名单内,重试
|
|
421
436
|
const { retryFlag, retryApiWhiteMap, requestRetryCount } = wx.tmsFlagMap || {};
|
|
422
437
|
const isWhiteApi = retryApiWhiteMap?.home === 'all' ? true : (retryApiWhiteMap?.home || []).includes(path);
|
|
423
438
|
const canRetry = errno => RETRY_WX_ERR_NOS.includes(errno) && isWhiteApi;
|
|
@@ -620,6 +635,9 @@ const isPathNeedRetryLogin = (path) => {
|
|
|
620
635
|
return noRetryPaths.every(noRetryPath => !path.includes(noRetryPath));
|
|
621
636
|
};
|
|
622
637
|
|
|
638
|
+
// 判断网关框架码是否需要重试
|
|
639
|
+
const isGatewayCodeNeedRetry = gatewayCode => (gatewayCode > 0 && gatewayCode <= 999) || +gatewayCode === 5000;
|
|
640
|
+
|
|
623
641
|
let refreshPromise;
|
|
624
642
|
async function loginRefresh() {
|
|
625
643
|
if (!refreshPromise) {
|