@tmsfe/tms-core 0.0.193 → 0.0.196
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/location/utils.ts +20 -21
- package/src/request.js +15 -3
- package/src/wxApi.ts +38 -0
package/package.json
CHANGED
package/src/location/utils.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import EventDispatcher from '../eventDispatcher';
|
|
6
|
+
import { getWxSetting } from '../wxApi';
|
|
6
7
|
|
|
7
8
|
const event = new EventDispatcher();
|
|
8
9
|
|
|
@@ -80,27 +81,25 @@ export function getSetting(scopeKey: string = LocationScopeKey) {
|
|
|
80
81
|
return getSettingPromise;
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
});
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
85
|
+
getSettingPromise = new Promise(async (resolve, reject) => {
|
|
86
|
+
// 历史逻辑:这里需要每次调用都获取最新的setting —— 后续评估优化
|
|
87
|
+
const settingRes = await getWxSetting(true);
|
|
88
|
+
const { success, errMsg = '', authSetting } = settingRes;
|
|
89
|
+
if (success) {
|
|
90
|
+
resolve((authSetting as any)?.[scopeKey]);
|
|
91
|
+
getSettingPromise = null;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
getSettingPromise = null;
|
|
95
|
+
// wx.getSetting接口没有响应时errMsg
|
|
96
|
+
const reason = 'getSetting:fail data no response';
|
|
97
|
+
// 部分机型上,wx.getSetting接口没有响应,此时,当做位置开关是打开的来处理
|
|
98
|
+
if (errMsg.indexOf(reason) > -1) {
|
|
99
|
+
resolve(true);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
reject(settingRes);
|
|
104
103
|
});
|
|
105
104
|
|
|
106
105
|
return getSettingPromise;
|
package/src/request.js
CHANGED
|
@@ -15,7 +15,18 @@ import { encryptObjInit } from './encrypt/index';
|
|
|
15
15
|
import reporter from './report/index';
|
|
16
16
|
import logger from './logger';
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// 微信底层错误重试码 600001-微信cronet组件错误 600003-网络中断 5-接口超时
|
|
19
|
+
export const RETRY_WX_ERRNO_MAP = {
|
|
20
|
+
600001: {
|
|
21
|
+
waitTime: 500,
|
|
22
|
+
},
|
|
23
|
+
600003: {
|
|
24
|
+
waitTime: 300,
|
|
25
|
+
},
|
|
26
|
+
5: {
|
|
27
|
+
waitTime: 500,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
19
30
|
|
|
20
31
|
/**
|
|
21
32
|
* 用于序列化需要签名的参数
|
|
@@ -391,15 +402,16 @@ export default class Request {
|
|
|
391
402
|
// 微信系统errno:在重试码白名单内,重试
|
|
392
403
|
const { retryFlag, retryApiWhiteMap } = wx.tmsFlagMap || {};
|
|
393
404
|
const isWhiteApi = retryApiWhiteMap?.home === 'all' ? true : (retryApiWhiteMap?.home || []).includes(path);
|
|
394
|
-
const canRetry = errno =>
|
|
405
|
+
const canRetry = errno => RETRY_WX_ERRNO_MAP[errno] && isWhiteApi;
|
|
395
406
|
if (retryFlag && canRetry(err?.errno)) {
|
|
407
|
+
const waitTime = RETRY_WX_ERRNO_MAP[err.errno]?.waitTime || 300;
|
|
396
408
|
return await this.handleReTry(path, param, method, header, {
|
|
397
409
|
reportMsg: {
|
|
398
410
|
errno: err.errno,
|
|
399
411
|
errMsg: err.errMsg,
|
|
400
412
|
},
|
|
401
413
|
// maxRetryCount: 2, // 先立即重试一次,失败再延时重试一次
|
|
402
|
-
waitTime
|
|
414
|
+
waitTime, // 微信底层错误300ms后重试一次
|
|
403
415
|
isSuccess: retryRes => !canRetry(retryRes?.errno),
|
|
404
416
|
});
|
|
405
417
|
}
|
package/src/wxApi.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微信API工具类
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* getSetting
|
|
7
|
+
* @param forceRefresh 是否强制刷新
|
|
8
|
+
*/
|
|
9
|
+
async function getWxSetting(forceRefresh = false): Promise<{
|
|
10
|
+
success: boolean; // 是否成功
|
|
11
|
+
errMsg?: string, // message
|
|
12
|
+
authSetting?: { // 用户设置
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
subscriptionsSetting?: {
|
|
16
|
+
mainSwitch: boolean; // 订阅消息总开关
|
|
17
|
+
itemSettings?: { // 每一项开关
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}> {
|
|
22
|
+
if (wx.tmsGetWxSetting && !forceRefresh) {
|
|
23
|
+
return wx.tmsGetWxSetting;
|
|
24
|
+
}
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
const cacheData = (data, success) => {
|
|
27
|
+
wx.tmsGetWxSetting = { ...(data || {}), success };
|
|
28
|
+
resolve(wx.tmsGetWxSetting);
|
|
29
|
+
};
|
|
30
|
+
wx.getSetting({
|
|
31
|
+
withSubscriptions: true,
|
|
32
|
+
success: res => cacheData(res, true),
|
|
33
|
+
fail: err => cacheData(err, false),
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { getWxSetting };
|