@qiu_jun/monitors 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -88,3 +88,5 @@ npm publish
88
88
  - 性能类(paint/timing/longTask)→ `exc_perf_event`
89
89
  - reporter 源码位于 `src/exception/`,与 exception-sdk 逻辑等价,便于独立发版
90
90
  - **后台对接与展示**:[backend-integration.md](./backend-integration.md)(与 exception 模块 `/api/exception/*` 接口一一对照)
91
+
92
+ # npm login --registry=https://registry.npmjs.org/
@@ -75,6 +75,12 @@ function wrapLifecycle(fn, name, getContext) {
75
75
  }
76
76
  /** wrapLifecycle 上报出口(由 createMiniProgramMonitor 注入) */
77
77
  let lifecycleErrorHandler = null;
78
+ /** 不上报的消息关键字:小程序提审/平台侧产生的导航失败噪声(如 navigateTo:fail page xxx.html is not found) */
79
+ const IGNORED_MESSAGE_KEYWORDS = ['.html is not found'];
80
+ /** 命中关键字的消息不上报 */
81
+ function isIgnoredMessage(message) {
82
+ return IGNORED_MESSAGE_KEYWORDS.some(keyword => message.includes(keyword));
83
+ }
78
84
  /** 短窗口内同消息去重(生命周期包装抛出 + wx.onError 会收到同一条错误) */
79
85
  let lastErrorCache = { message: '', time: 0 };
80
86
  function isDuplicate(message) {
@@ -205,6 +211,9 @@ function createMiniProgramMonitor(options) {
205
211
  });
206
212
  };
207
213
  const onError = (message) => {
214
+ // 提审等平台侧噪声(如 navigateTo:fail page xxx.html is not found)不上报
215
+ if (isIgnoredMessage(message))
216
+ return;
208
217
  // 生命周期包装已上报过的错误(包装后原样抛出会再进这里),5s 内同消息去重
209
218
  if (isDuplicate(message))
210
219
  return;
@@ -215,9 +224,13 @@ function createMiniProgramMonitor(options) {
215
224
  var _a;
216
225
  const reason = res.reason;
217
226
  const err = reason instanceof Error ? reason : undefined;
227
+ const message = (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : (typeof reason === 'string' ? reason : JSON.stringify(reason));
228
+ // 平台噪声消息同样过滤
229
+ if (isIgnoredMessage(message))
230
+ return;
218
231
  reporter.capture(withBase({
219
232
  type: 'unhandledrejection',
220
- message: (_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : (typeof reason === 'string' ? reason : JSON.stringify(reason)),
233
+ message,
221
234
  stack: err === null || err === void 0 ? void 0 : err.stack,
222
235
  }));
223
236
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qiu_jun/monitors",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "前端监控,用于捕获,分析,和报告网站或应用程序中的异常,错误和性能问题的方法",
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",