
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
caught-core
Advanced tools
<script src="https://unpkg.com/caught-core"></script>
npm install caught-core -save
// 直接引入脚本 (Import scripts directly)
var caught = window.createCaught({
//...options
errorHandler: (errs) => {
console.log('错误列表:', errs)
},
plugins: []
})
var createCustomInsert = caught.createCustomInsert
var proxyCaught = caught.proxyCaught
// 使用npm包 (Use NPM package)
import createCaught from 'caught-core'
const { createCustomInsert, proxyCaught } = createCaught({
//...options
errorHandler: (errs) => {
console.log('错误列表:', errs)
},
plugins: []
})
| 选项名 | 用途 | 类型 | 默认值 |
|---|---|---|---|
| sameLimit | 批量上传模式时,相同错误的最大载入限制 (Max load limit for the same error in batch upload mode) | number | 10 |
| retry | 是否开启处理失败重试模式 (Whether to enable retry after processing failure) | boolean | true |
| retryTime | 失败重试的间隔时间, 单位毫秒 (Retry interval, in milliseconds) | number | 5000 |
| failMaxNum | 最大失败次数,超出则停止捕获 (Maximum number of failures, beyond which capture stops) | number | 5 |
| listeners | 是否启用错误事件监听功能 (Whether to enable error event listening) | boolean or object | true |
| errorHandler | 信息处理方法,必传项 (Information processing method, must pass) | function | - |
| plugins | 插件配置项 (Plug-in configuration items) | array | [] |
| sync | 是否开启同步捕获 (Whether to enable synchronization capture) | boolean | fasle |
除errorHandler外,其他都是可选项 (All except errorHandler are optional)
{
errorHandler(infoList, notify) {
axios.post(url, data: infoList)
.then(() => {
notify(true)
})
.catch(() => {
notify(false)
})
}
}
${type}-${flag}-${index}${extra && '-' + extra}, index存在是考虑到相同参数的createCustomInsert会被调用多次,此时通过index来标识唯一性
createCustomInsert 返回一个customInsertInfo方法,开发者可通过此方法,将自定义的错误信息加入到 caught的调度系统中
// 示例
const customInsertInfo = createCustomInsert('http', 'get')
axios(args).catch(err => {
customInsertInfo({
error: err,
meta: {
arges
}
})
})
function userHandle() {
// 假设出现了任何未捕获的错误(Any uncaught errors occurred)
}
const proxyUserHandle = proxyCaught(userHandle, {
flag: 'todo'
})
proxyUserHandle()
// 此时proxyUserHandle将自动捕获到userHandle中的错误,并交给caught的调度系统处理
// 代理配置
type proxyConfig = {
flag: any, // 错误标识
withArgs?: boolean, // 捕获到的错误是否携带参数
others?: any, // 其他开发者自定义信息
} | string // 代理配置可传入一个字符串,caught内部将默认识别为flag
| 钩子名 | 用途 | 参数 |
|---|---|---|
| addInfo | caught默认只收集部分重要信息,若需要自定义额外信息,可通过次钩子添加 (Caught Collects only some important information by default. If you need to customize additional information, you can add it using the secondary hook ) | info |
| fail | 处理失败时的钩子 (Handle failed hooks) | infoList |
| success | 处理成功时的钩子 (Handle success hooks) | infoList |
| jsError | js error 事件触发时的钩子 (js Error the hook when the event is raised) | info, event |
| staticError | 静态资源加载 error 事件触发时的钩子 (Static resource loading hooks when the error event is raised) | info, event |
| promiseRejection | 未catch的promsie (Did not catch promsie) | info, event |
| schedulable | 调度机制初始化完成时的钩子 (oks for scheduling mechanism initialization when complete) | createCustomInsert |
class PluginDemo {
apply(register) { // register 用于hook注册
const handler = info => {
const { type, flag, error, meta } = info
return {
myInfo: {
name: 'meili',
}
}
// 返回的对象将与原info中的meta信息合并
}
register.addInfo('add-info-plugin', handler) // 注册 addInfo 钩子, handler为回调函数
}
}
createCaught({
//...options
plugins: [
new PluginDemo()
]
})
interface Info {
type: string // 错误类型
flag: string // 内部生成的错误标识 `${type}-${flag}-${index}${extra && '-' + extra}`
meta?: Meta | Meta[] // 额外的信息,比如proxyCaught可选的一些信息:proxyCaught: { args, others }
count?: number // 同一错误出现的次数
error?: any // 错误信息
message?: string // error事件对象中的 message
filename?: string // error事件对象中的 filename (文件名)
lineno?: number // error事件对象中的 lineno (行)
colno?: number // error事件对象中的 colno (列)
time?: number // 错误捕获的时间戳(ms)
}
FAQs
A tool for JS error capture
We found that caught-core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.