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 🙏

© 2025 – Pkg Stats / Ryan Hefner

egg-error

v0.1.4

Published

load error configs

Readme

egg-error

NPM version build status Test coverage David deps Known Vulnerabilities npm download

依赖说明

依赖的 egg 版本

egg-error 版本 | egg 1.x --- | --- 1.x | 😁 0.x | ❌

依赖的插件

开启插件

// config/plugin.js
exports.error = {
  enable: true,
  package: 'egg-error',
};

使用场景

  • Why:

    • 因为业务场景下,报错信息不完整,缺失,个性丰富,所以萌生了此项目。
    • 将爆破错信息收口至同一场景,统一约定统一入口,同时要体现约定而非配置。
  • and What:

    • 有统一的配置,在 app/error/ 文件夹下统一配置
    • 使用时,在service层绑定在ctx下直接使用
  • How:

    • 配置错误信息:
      // app/error/order/demo.js
      // @param {number} code          业务报错代码
      // @param {string} errorMsg      业务错误报错
      // @param {number} statusCode    ctx http status code return
      // @param {string} msg           ctx 返回错误信息
      // @param {function} after         事后处理 ctx, eggError(错误配置信息)
      module.exports.testError = {
               code: "100010",
               errorMsg: "这里是业务${business}报错:${bsMessage}",
               statusCode: "500",
               msg: "不好意思。${userErrorType},请重试${business}",
               after: (ctx, eggError) =>{....}
      }
    • 基本使用:
      class HomeController extends Controller {
      async index() {
          const {ctx} = this;
          const error = ctx.error.order.demo.testError({
              business: "预定", bsMessage: "JSON Invalid", userErrorType: "提交数据不完整"
          });

    输出

    >>> 2022-08-05 15:58:35,059 ERROR 17395 [-/127.0.0.1/-/16ms GET /] [order|demo] [100010] 这里是业务预定报错:JSON Invalid
      
    • 返回的error结构
      • afterResult {any}
          // after {optional function} 配置返回的结果
          error.afterResult 
      • throw {function}
          // 可以抛出异常,使用的是 ctx.throw
          error.throw();
        • 输出
          2022-08-05 16:06:05,037 ERROR 18145 [-/127.0.0.1/-/20ms GET /] nodejs.InternalServerError: 不好意思。提交数据不完整,请重试预定
           at Object.throw (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/koa/lib/context.js:97:11)
           at Object.throw (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/egg-error/lib/baseError.js:53:38)
           at HomeController.index (/Users/xx/Documents/Codes/js/demoeggorder/app/controller/home.js:13:16)
           at Object.callFn (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/egg-core/lib/utils/index.js:44:21)
           at Object.classControllerMiddleware (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/egg-core/lib/loader/mixin/controller.js:87:20)
           at Object.callFn (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/@eggjs/router/lib/utils.js:12:21)
           at wrappedController (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/@eggjs/router/lib/egg_router.js:322:18)
           at dispatch (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/koa-compose/index.js:44:32)
           at next (/Users/xx/Documents/Codes/js/demoeggorder/node_modules/koa-compose/index.js:45:18)
           at /Users/xx/Documents/Codes/js/demoeggorder/node_modules/@eggjs/router/lib/router.js:186:18
          message: "不好意思。提交数据不完整,请重试预定"
          pid: 18145
          hostname: MacBook-Pro.local
            
            
            

详细配置 (无)

单元测试(无)

提问交流

请到 egg issues 异步交流。

License

MIT