From 2fa424ef40894f8d41787abc772795a817d1fbba Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Fri, 15 May 2026 21:19:09 +0200 Subject: [PATCH 1/2] feat(rpc): implement wrapBroadcast function to enhance RPC error handling --- src/runtime/core/rpc.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/runtime/core/rpc.ts b/src/runtime/core/rpc.ts index 15edabe..04616a1 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) } From 07a37bc89bdf909927eee01e61e4bf6ada4f9280 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Sat, 16 May 2026 14:43:03 +0200 Subject: [PATCH 2/2] chore: lint --- src/runtime/core/rpc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/core/rpc.ts b/src/runtime/core/rpc.ts index 04616a1..2e3973b 100644 --- a/src/runtime/core/rpc.ts +++ b/src/runtime/core/rpc.ts @@ -15,7 +15,7 @@ function wrapBroadcast(rpc: HintsClientFunctions): HintsClientFunctions { } return result } - catch(error) { + catch (error) { console.debug(error) } }