export default {
  /**
   * 初始化全局报错监听
   * @param {Function} listener 
   */
  initListener(listener) {
    const defaultErrorHandler = global.ErrorUtils.getGlobalHandler();

    global.ErrorUtils.setGlobalHandler(e => {
      if (typeof listener === 'function') {
        listener({
          message: e.message,
          line: e.line,
          column: e.column,
          stack: e.stack,
          sourceURL: e.sourceURL,
          Error: e
        });
      }
      defaultErrorHandler(e);
    });
  }
}