@busyhe/ynn-plugin-exception

0.0.1 • Public • Published

@busyhe/ynn-plugin-exception

前端服务异常处理通用模块

各模块自定义Errors规则

各个模块自定义Errors的code,不可以使用1000之前的数字,格式如下:

{
    CUSTOM_ERROR : {
        code : 1000,
        message : 'custom error message'
    }
}

Installation

$ npm install --save @busyhe/ynn-plugin-exception

Usage

const Ynn = require( 'ynn' );
const app = new Ynn( {
    root : __dirname,
    debugging : Ynn.DEBUGGING_DANGER,
    logging : false,
    plugins : {
        Exception : {
            path : '@busyhe/ynn-plugin-exception',
            options : {
                // 也可以通过 config/errors.js 进行配置
                errors : {
                    CUSTOM_ERROR : {
                        code : 1000,
                        message : 'custom error message'
                    }
                }
            }
        }
    }
} );

app.use( () => {
    throw new app.Exception( 'CUSTOM_ERROR' );
} );

上面代码在接收到请求后,将返回:

{
    status : 1,
    errno : 1000,
    message : 'custom error message'
}

Package Sidebar

Install

npm i @busyhe/ynn-plugin-exception

Weekly Downloads

0

Version

0.0.1

License

none

Unpacked Size

7.61 kB

Total Files

9

Last publish

Collaborators

  • busyhe