filters

通过配置filters属性,用户可以过滤掉一些不需要捕获的错误,例如:

  1. fundebug.init(
  2. {
  3. apikey: "API-KEY",
  4. filters: [
  5. {
  6. message: /Cannot read property/
  7. },
  8. {
  9. req:
  10. {
  11. method: /^POST$/
  12. }
  13. }]
  14. });

配置规则

filters属性有以下特点:

  • 它是一个数组,数组中的元素为过滤规则,当错误符合数组中任意一条过滤规则时,则会被过滤
  • 过滤规则是JavaScript对象,该对象的Key为错误的属性名,Value为正则表达式(唯一的特例是”inexistence”);
  • 当错误的属性匹配对应正则表达式时,则会被过滤;
  • 当过滤规则的属性值为”inexistence”时,则会过滤某个属性不存在的错误;

错误事件示例:

测试Fundebug时,在微信开发者工具的调试器中,可以在Network中看到发送到https://wegame.fundebug.net/event/的网络请求,这个请求的body就是我们捕获的错误事件

  1. {
  2. "name": "ReferenceError",
  3. "message": "b is not defined",
  4. "stack": "ReferenceError: b is not defined\n at http://127.0.0.1:14988/game/game.js:80:5\n at require (http://127.0.0.1:14988/game/__dev__/WAGame.js:3:13718)\n at http://127.0.0.1:14988/game/gamePage.html:149:5",
  5. "type": "caught",
  6. "metaData":
  7. {
  8. "name": "Fundebug",
  9. "nation": "China"
  10. },
  11. "notifierVersion": "0.2.0",
  12. "apikey": "95e68fb61776cb5f9e8a610b20d0bdee89b52bddd5b442ddfcc022a2911780f1",
  13. "releaseStage": "development",
  14. "appVersion": "3.2.5",
  15. "systemInfo":
  16. {
  17. "errMsg": "getSystemInfo:ok",
  18. "model": "iPhone 5",
  19. "pixelRatio": 2,
  20. "windowWidth": 320,
  21. "windowHeight": 568,
  22. "system": "iOS 10.0.1",
  23. "language": "zh_CN",
  24. "version": "6.6.3",
  25. "screenWidth": 320,
  26. "screenHeight": 568,
  27. "SDKVersion": "2.0.9",
  28. "brand": "devtools",
  29. "fontSizeSetting": 16,
  30. "benchmarkLevel": 1,
  31. "batteryLevel": 100,
  32. "statusBarHeight": 20,
  33. "platform": "devtools"
  34. },
  35. "time": 1528937703693
  36. }

配置示例

示例1:过滤ReferenceError的错误

  1. fundebug.init(
  2. {
  3. apikey: "API-KEY",
  4. filters: [
  5. {
  6. name: /ReferenceError/
  7. }]
  8. });

示例2:不监控发送到example.com的GET请求错误

  1. fundebug.init(
  2. {
  3. apikey: "API-KEY",
  4. filters: [
  5. {
  6. req:
  7. {
  8. url: /example\.com/,
  9. method: /^GET$/
  10. }
  11. }]
  12. });

示例3:过滤statusCode为401的HTTP请求错误

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. res: {
  6. statusCode: /^401$/
  7. }
  8. }]
  9. })

示例4:过滤iPhone5上的ReferenceError

  1. fundebug.init(
  2. {
  3. apikey: "API-KEY",
  4. filters: [
  5. {
  6. name: /^ReferenceError$/,
  7. systemInfo:
  8. {
  9. "model": /^iPhone 5$/,
  10. }
  11. }]
  12. });

示例5:配置多条过滤规则

  1. fundebug.init(
  2. {
  3. apikey: "API-KEY",
  4. filters: [
  5. {
  6. scene: /^1002$/
  7. },
  8. {
  9. message: /TEST 02/,
  10. scene: /1001/
  11. }]
  12. });s