Vue global error handler that shows toast notifications and logs unhandled errors.
// Source: https://github.com/mateaix/matecloud | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import { MateMessage } from '@matecloud/ui'
import type { App } from 'vue'
import { BizError } from '@matecloud/core'
/**
* 全局错误网 —— 与 useAsync 的逐请求错误处理互补的最后一道防线:
* 捕获 Vue 渲染/生命周期里未被 try-catch 的异常, 以及全局 unhandledrejection,
* 统一降级为可读 toast + 结构化 console 分组, 杜绝"白屏无提示"。
*
* 设计: 已被业务层处理过的错误 (BizError, 多由 useAsync.onError 透出) 不再二次弹窗;
* 节流防止同类错误刷屏; 401/403 已由 api client 的 CustomEvent 接管, 这里只兜真正未处理的。
*/
const THROTTLE_MS = 3000
let lastShownAt = 0
let lastMessage = ''
function notify(message: string, raw: unknown) {
const now = Date.now()
// 同消息 3s 内只弹一次, 防循环报错刷屏
if (message ===
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key