1.0.26 • Published 5 years ago

@incpad/error-handle v1.0.26

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Usage

    const ErrorHandle = require('./packages/error-handle');
    const list=[
        {
            code: 1001,
            msg: 'Path not valid',
            name: 'PathNotValid',
        }
    ]
    const ErrorHandleInstance=new ErrorHandle()
    ErrorHandleInstance.initCustomErrorWithObject(list)

可以选择使用code或者name去触发一个error,使用如下方式触发:

ErrorHandleInstance.throwErrorByName("PathNotValid")
ErrorHandleInstance.throwErrorByCode(1001)

在错误定义时可选属性为handleFunc,传入一个函数,该函数会在错误触发之前调用

{
        code: 1001,
        msg: 'Path not valid',
        name: 'PathNotValid',
        handleFunc:e=>{
            //send error to sentry
        }
}