caught-core
Version:
A tool for JS error capture
51 lines (46 loc) • 1.14 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
<script src="../dist/caught-global.js" ></script>
</head>
<body>
<img src="static-error" alt="">
<script>
class PluginDemo {
apply(register) { // register 用于hook注册
const handler = info => {
const { type, flag, error, meta } = info
return {
myInfo: {
name: `${String(error)}meili`,
}
}
}
register.addInfo('add', handler) // 注册 addInfo 钩子
}
}
const caught = createCaught({
errorHandler: (errs) => {
console.log('错误:', errs)
},
plugins: [
new PluginDemo()
]
})
const fn = caught.proxyCaught(() => {
throw 'a proxy function error'
})
try {
fn()
} catch (error) {
fn()
}
Promise.reject('no catch')
throw 'a js error'
</script>
</body>
</html>