You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
3 months ago | |
---|---|---|
.. | ||
__tests__ | 3 months ago | |
config | 3 months ago | |
src | 3 months ago | |
stories | 3 months ago | |
README.md | 3 months ago | |
eslint.config.js | 3 months ago | |
package.json | 3 months ago | |
tsconfig.build.json | 3 months ago | |
tsconfig.json | 3 months ago | |
tsconfig.misc.json | 3 months ago | |
vitest.config.ts | 3 months ago |
README.md
@coze-arch/bot-error 使用文档
安装
cd ${path/to/project}
rush add @coze-arch/bot-error
使用
提供了一些用于错误处理的工具。
CustomError
CustomError 是一个自定义错误类,用来代替原生的Error,使用 throw new CustomerError抛出的错误会上报到slardar的自定义事件中,使用方可以根据需要进行监控处理,不会统计到jsError
import { CustomError } from '@coze-arch/bot-error';
throw new CustomError('parmasValidation', 'empty copy');
isCustomError
isCustomError 是一个函数,它可以检查一个错误是否是 CustomError
import { isCustomError, CustomError } from '@coze-arch/bot-error';
const myError = new CustomError('parmasValidation', 'empty copy');
console.log(isCustomError(error)); // 输出:true
useErrorCatch
useErrorCatch 是一个 React Hook,它可以帮助你在组件中捕获和处理错误。
- 监听全局 unhandledrejection、error 事件,上报相关内容由业务侧自行补充
- 对于已知错误,上报自定义事件进行监控