Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/runtime/core/rpc.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>).catch === 'function') {
;(result as Promise<unknown>).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)
}
Loading