@tmsfe/tms-core 0.0.199 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.199",
3
+ "version": "0.0.202",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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, benchmarkLevel, system, memorySize } = currentSystemInfo;
48
- systemInfo = { model, wxVersion, platform, SDKVersion, host, benchmarkLevel, system, memorySize };
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
- // 处理token失效情况(errcode=35)
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
- // 微信系统errno:在重试码白名单内,重试
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;
@@ -574,7 +589,7 @@ export default class Request {
574
589
  * @returns {Promise} 返回 wx.request 的 requestTask
575
590
  */
576
591
  async createStreamRequestTask(path, params = {}) {
577
- const { param = {}, method = 'POST', header = {}, callbacks = {} } = params;
592
+ const { param = {}, method = 'POST', header = {}, callbacks = {}, timeout = 60000 } = params;
578
593
  const requestParam = await composeParam(param, this.withAuth, this.baseParam);
579
594
  const data = sign(requestParam, this.secretKey);
580
595
 
@@ -586,6 +601,7 @@ export default class Request {
586
601
  header,
587
602
  method,
588
603
  data,
604
+ timeout,
589
605
  enableHttp2: this.enableHttp2,
590
606
  enableChunked: this.enableChunked,
591
607
  responseType: this.responseType,
@@ -619,6 +635,9 @@ const isPathNeedRetryLogin = (path) => {
619
635
  return noRetryPaths.every(noRetryPath => !path.includes(noRetryPath));
620
636
  };
621
637
 
638
+ // 判断网关框架码是否需要重试
639
+ const isGatewayCodeNeedRetry = gatewayCode => (gatewayCode > 0 && gatewayCode <= 999) || +gatewayCode === 5000;
640
+
622
641
  let refreshPromise;
623
642
  async function loginRefresh() {
624
643
  if (!refreshPromise) {