You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a server function fails, the server does not throw an exception but instead sends a JSONRPCError to the client, making the error unobservable by default. To handle server errors, you can wrap the server function as follows:
89
+
90
+
```ts
91
+
import {
92
+
JSONRPCInvalidParamsError,
93
+
typeJSONRPCMethod,
94
+
typeJSONRPCMethods,
95
+
JSONRPCServer,
96
+
} from'@yieldray/json-rpc-ts'
97
+
98
+
function wrapMethod<T, U>(fn:JSONRPCMethod<T, U>):JSONRPCMethod<T, U> {
99
+
returnasync (arg) => {
100
+
try {
101
+
console.log('Request', arg, fn)
102
+
const result =awaitfn(arg)
103
+
console.log('Response', result)
104
+
returnresult
105
+
} catch (e) {
106
+
console.error('Error', e)
107
+
throwe
108
+
}
109
+
}
110
+
}
111
+
112
+
function wrapMethods(methods:JSONRPCMethods):JSONRPCMethods {
0 commit comments