@incpad/error-handle
v1.0.26
Published
```$xslt const ErrorHandle = require('./packages/error-handle'); const list=[ { code: 1001, msg: 'Path not valid', name: 'PathNotValid', } ] const ErrorHandleInstance=new ErrorHandle()
Downloads
3
Readme
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
}
}