diff --git a/src/runtime/core/rpc.ts b/src/runtime/core/rpc.ts index 15edabe..2e3973b 100644 --- a/src/runtime/core/rpc.ts +++ b/src/runtime/core/rpc.ts @@ -1,5 +1,30 @@ import type { HintsClientFunctions } from './rpc-types' +function wrapBroadcast(rpc: HintsClientFunctions): HintsClientFunctions { + return new Proxy(rpc, { + get(target, prop, receiver) { + const value = Reflect.get(target, prop, receiver) + if (typeof value !== 'function') return value + return (...args: unknown[]) => { + try { + const result = (value as (...a: unknown[]) => unknown).apply(target, args) + if (result && typeof (result as Promise).catch === 'function') { + ;(result as Promise).catch((e) => { + console.debug(e) + }) + } + return result + } + catch (error) { + console.debug(error) + } + } + }, + }) +} + export function getRPC(): HintsClientFunctions | undefined { - return globalThis.__nuxtHintsRpcBroadcast + const rpc = globalThis.__nuxtHintsRpcBroadcast + if (!rpc) return undefined + return wrapBroadcast(rpc) }