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<
190190 return ;
191191 }
192192
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+ ) ;
198201 }
199202
200203 private _onrequest ( request : JSONRPCRequest ) : void {
@@ -222,7 +225,9 @@ export abstract class Protocol<
222225 const abortController = new AbortController ( ) ;
223226 this . _requestHandlerAbortControllers . set ( request . id , abortController ) ;
224227
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 } ) )
226231 . then (
227232 ( result ) => {
228233 if ( abortController . signal . aborted ) {
You can’t perform that action at this time.
0 commit comments