@tmsfe/tms-core 0.0.112 → 0.0.114

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/request.js +37 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.112",
3
+ "version": "0.0.114",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/request.js CHANGED
@@ -312,43 +312,52 @@ export default class Request {
312
312
  const requestParam = await composeParam(param, this.withAuth, this.baseParam);
313
313
  const data = sign(requestParam);
314
314
  return new Promise((resolve, reject) => {
315
+ const requestTime = Date.now();
316
+ const printLog = (isSuccess, res) => {
317
+ // 埋点已经单独打日志了,接口请求数据日志太长影响分析
318
+ if (path.indexOf('basic/event/upload') !== -1) {
319
+ return;
320
+ }
321
+
322
+ let result = JSON.stringify(res);
323
+ // 打车日志不截断,方便用于回放
324
+ if (isSuccess && path.indexOf('/takecar/') === -1 && result.length > 500) {
325
+ result = `${result.substring(0, 500)} 内容太长被截断`;
326
+ }
327
+
328
+ const obj = {
329
+ path,
330
+ method,
331
+ header: JSON.stringify(header),
332
+ params: JSON.stringify(data),
333
+ duration: Date.now() - requestTime,
334
+ };
335
+ if (isSuccess) {
336
+ obj.res = result;
337
+ } else {
338
+ obj.err = result;
339
+ }
340
+
341
+ const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
342
+ if (isSuccess) {
343
+ logger.log(`接口请求成功:\n${str}`);
344
+ } else {
345
+ logger.warn(`接口请求失败:\n${str}`);
346
+ }
347
+ };
348
+
315
349
  wx.request({
316
350
  url: this.makeUrl(path),
317
351
  header,
318
352
  method,
319
353
  data,
354
+ enableHttp2: true,
320
355
  success: (res) => {
321
- // 埋点已经单独打日志了,接口请求数据日志太长影响分析
322
- if (path.indexOf('basic/event/upload') === -1) {
323
- let result = JSON.stringify(res?.data);
324
- // 打车日志不截断,方便用于回放
325
- if (path.indexOf('/takecar/') === -1 && result.length > 500) {
326
- result = `${result.substring(0, 500)} 内容太长被截断`;
327
- }
328
- const obj = {
329
- path,
330
- method,
331
- header: JSON.stringify(header),
332
- params: JSON.stringify(data),
333
- res: result,
334
- };
335
- const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
336
- logger.log(`接口请求成功:\n${str}`);
337
- }
338
-
356
+ printLog(true, res.data);
339
357
  resolve(res);
340
358
  },
341
359
  fail: (err) => {
342
- const obj = {
343
- path,
344
- method,
345
- header: JSON.stringify(header),
346
- params: JSON.stringify(data),
347
- err: JSON.stringify(err),
348
- };
349
- const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
350
- logger.warn(`接口请求失败:\n${str}`);
351
-
360
+ printLog(false, err);
352
361
  reject(err);
353
362
  },
354
363
  });