1.0.1 • Published 5 years ago

@hfaxjs/bug-report v1.0.1

Weekly downloads
6
License
ISC
Repository
-
Last release
5 years ago

Introduce

@hfaxjs 错误上报插件,原则上每个外部项目需要集成。 项目初创滴滴王晨雨<wangchenyu-pbj@hfax.com>申请apikey。

Getting Started

需要安装@hfaxjs/core 核心库

cnpm install @hfaxjs/core --save
cnpm install @hfaxjs/bug-report --save

Usage

import hfax from '@hfaxjs/core';
import bugReport from '@hfaxjs/bug-report';
import Vue from 'vue';

hfax.use(bugReport, {
  apikey: process.env.VUE_APP_HFAXJS_BUGREPORT_APIKEY, //必填
  releasestage: process.env.NODE_ENV,
  isVue: true  //当使用vue框架时,需要第三个参数传入Vue实例
}, Vue)

// test 
hfax.bugReport.notify('Test', 'it works!') //测试,生效需要删除

Configuration

export interface bugReportConfig{
    apikey: string;  //必填,apikey
    appversion?: string; //app 应用指定版本
    releasestage?: string; //环境区分 development test production
    user?: string;  //用户属性 可忽略
    metaData?: object; //可以通过metaData收集所需要的信息 见doc https://docs.fundebug.com/notifier/javascript/customize/metadata.html
    callback?: Function;    //错误回到上报到其他数据平台(暂无)
    setHttpBody?: boolean;
    httpTimeout?: number;
    filters?: object[];
    silent?: boolean;  //
    silentDev?: boolean; //开发阶段不报错
    silentResource?: boolean;
    silentHttp?: boolean;
    silentWebsocket?: boolean;
    silentConsole?: boolean;
    silentPerformance?: boolean;
    sampleRate?: number;
    domain?: string;
    //hfax 扩展字段 
    isVue?:boolean; //是否是vue框架,需要加载时候传入Vue实例
}

Api

notify(name, message, option)

使用 hfax.bugReport.notify()方法,可以将自定义的错误信息发送到错误平台

name: 错误名称,参数类型为字符串

message: 错误信息,参数类型为字符串

option: 可选对象,参数类型为对象,用于发送一些额外信息,比如:

  • metaData: 其他自定义信息

示例:

1.不带 metaData

  hfax.bugReport.notify("Test", "Hello, Fundebug!");

2.带 metaData

   hfax.bugReport.notify("Test", "Hello, Fundebug!", {
        metaData: {
            company: "云麒",
            location: "厦门"
        }
    });

notifyError(error, option)

使用 notifyError()方法,可以将主动捕获的错误发送到 Fundebug

error:抛出的错误对象,参数类型为Error

option:可选对象,参数类型为对象,用于发送一些额外信息,比如:

  • metaData: 其他自定义信息

例子同 notify

hfax.bugReport.notifyError()上报的错误的类型"caught",即type属性的值为"caught"。

Version

current version:1.0.1

Update

2019-10-22 version 1.0.1 修复构建错误 2019-10-22 version 1.0.0-stable