File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -190,11 +190,14 @@ export abstract class Protocol<
190
190
return ;
191
191
}
192
192
193
- handler ( notification ) . catch ( ( error ) =>
194
- this . _onerror (
195
- new Error ( `Uncaught error in notification handler: ${ error } ` ) ,
196
- ) ,
197
- ) ;
193
+ // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
194
+ Promise . resolve ( )
195
+ . then ( ( ) => handler ( notification ) )
196
+ . catch ( ( error ) =>
197
+ this . _onerror (
198
+ new Error ( `Uncaught error in notification handler: ${ error } ` ) ,
199
+ ) ,
200
+ ) ;
198
201
}
199
202
200
203
private _onrequest ( request : JSONRPCRequest ) : void {
@@ -222,7 +225,9 @@ export abstract class Protocol<
222
225
const abortController = new AbortController ( ) ;
223
226
this . _requestHandlerAbortControllers . set ( request . id , abortController ) ;
224
227
225
- handler ( request , { signal : abortController . signal } )
228
+ // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
229
+ Promise . resolve ( )
230
+ . then ( ( ) => handler ( request , { signal : abortController . signal } ) )
226
231
. then (
227
232
( result ) => {
228
233
if ( abortController . signal . aborted ) {
You can’t perform that action at this time.
0 commit comments