npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

error-reports

v0.0.7

Published

FE 异常上报

Downloads

9

Readme

前端异常上报

简介:从简单性、可测试性和松耦合性角度而言,绝大部分前端开发者都可以从error-report中受益。解决前端异常信息统一处理的痛点,error-report给复杂的前端异常上报带来了春天。记录前端异常信息,支持断网暂存异常,在线后自动上传暂存异常信息。涵盖 Vue 异常、Axios 异常、原生Ajax 异常、JS 抛出的异常、Promise 异常、Async 异常、加载第三方CDN资源异常等,几乎涵盖了前端所有能涉及到的异常。

  • 目的:解决前端异常信息统一处理的痛点
  • 功能:记录前端异常信息,支持断网暂存异常,在线后自动上传暂存异常信息
  • 范围:任何前端应用
  • 使用:两行代码搞定,使用的复杂度几乎降低到了零

特点

  • 可拔插
  • 代码侵入量小
  • 使用灵活方便

使用

import ErrorReport from "error-reports";

Vue.use(ErrorReport, {
    reportUrl: "http://localhost:10300/errorReport",
    env: "dev",
    appId: "error-report-5c6pz3e4il59k2f3b6",
    appName: "error-report"
});

Demo

examples

配置参数 options

属性|说明|类型|默认值|是否可以为空 --|:--:|--:|--:|--: reportUrl|异常上报地址|String|http://localhost:10300/errorReport|N| delayTime|延时上报Error时间|Number|3000 (单位:毫秒)|Y appId|项目ID|String||Y appName|项目名称|String||Y browser|浏览器名称|String|内部方法可以获取|N| device|设备名称|String|内部方法可以获取|N| userId|userId|String||Y| token|token|String||Y| timeSpan|发送数据时的时间戳|Number|每次取当前的时间戳|Y| infoType|信息类别,默认为error|String|type|Y| msg|错误的具体信息|String|错误的具体信息|Y| userAgent|userAgent|String|userAgent|Y| pageUrl|上报页面地址|String|window.location.href|Y| stack|错误堆栈信息|String|错误堆栈信息|Y| localStorageKey|建议使用固定的key,下次用户打开浏览器可以直接恢复异常数据并上传|String|localStorageKey|N| dev|环境:dev、test、uat、pro|String|开发环境|Y| data|更多错误信息|Object|更多错误信息|Y|

注意事项

考虑到有些项目使用原生Ajax,Ajax 异常做了原生的拦截,Axios 异常也做了拦截;使用了Axios的童鞋,会出现异常上报两次(原因:Axios 异常拦截器一次,原生Ajax异常 拦截一次),不想上报两次可以选择注释以下代码(Axios 异常监控Ajax 监控 其中任何一个即可)。 在error-report/src/plugins/errorReport.js中。

注释 Axios 异常监控,Axios异常 将不会被上报;

        // Axios 异常监控
        axios.interceptors.response.use(null, error => {
            this.options.msg = error.message;
            this.options.stack = this.processStackMsg(error);
            this.options.data = JSON.stringify({
                category: "Axios"
            });

            // 合并上报的数据,包括默认上报的数据和自定义上报的数据
            const reportData = Object.assign({}, this.options);
            this.saveReport(reportData);

            return Promise.reject(error);
        });

或者注释掉原生的 Ajax 监控 ,原生Ajax异常 将不会被上报。

        // Ajax监控
        const ajaxListener = {};
        // 复制send方法
        ajaxListener.tempSend = XMLHttpRequest.prototype.send;
        // 复制open方法
        ajaxListener.tempOpen = XMLHttpRequest.prototype.open;
        // 重写open方法,记录请求的url
        XMLHttpRequest.prototype.open = function(method, url, boolen) {
            ajaxListener.tempOpen.apply(this, [method, url, boolen]);
            this.ajaxUrl = url;
        };
        const self = this;
        // 发送
        XMLHttpRequest.prototype.send = function(data) {
            const tempReadystate = this.onreadystatechange;
            this.onreadystatechange = function() {
                if (this.readyState === 4) {
                    if (this.status >= 200 && this.status < 300) {
                        tempReadystate && tempReadystate.apply(this, [data]);
                        return;
                    }

                    self.options.msg = "AJAX 请求错误";
                    self.options.stack = `错误码:${this.status}`;
                    self.options.data = JSON.stringify({
                        requestUrl: this.ajaxUrl,
                        category: "XMLHttpRequest",
                        text: this.statusText,
                        status: this.status
                    });
                    // 合并上报的数据,包括默认上报的数据和自定义上报的数据
                    const reportData = Object.assign({}, self.options);
                    // 把错误信息发送给后台
                    self.saveReport(reportData);
                }
            };

            ajaxListener.tempSend.apply(this, [data]);
        };

具体情况,看需求!

具体情况,看需求!

具体情况,看需求!

重要事情说三遍!!!

警告

问题

  • 开发者有问题或者好的建议可以用Issues反馈交流,请给出详细信息。
  • 如果有问题需要提问,请在提问前先完成以下过程:
    • 请仔细阅读本项目文档,查看能否解决;
    • 请提问前尽可能做一些DEBUG或者思考分析,然后提问时给出详细的错误相关信息以及个人对问题的理解。

License

MIT Copyright (c) 2019 sky9102