How to report console.error with Sentry?

后端 未结 5 1270
孤独总比滥情好
孤独总比滥情好 2021-02-12 20:23

I have application where some critical issues are reported with console.error but are not thrown so application might continue to run - possibly in cri

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-12 20:53

    Found a little hacky solution:

    const consoleError = console.error;
    console.error = function(firstParam) {
      const response = consoleError.apply(console, arguments);
      Raven.captureException(firstParam, { level: 'error' });
      return response;
    };
    

    It just wraps console.error and report each of error logs in console to Raven (Sentry).

    If someone have nicer approach (maybe some hidden feature of Sentry) please feel free to share!

提交回复
热议问题