Odonno / ngrx-signalr-core

A library to handle realtime SignalR (.NET Core) events using @angular, rxjs and the @ngrx library
https://www.npmjs.com/package/ngrx-signalr-core
MIT License
27 stars 13 forks source link

Fix redundant error when starting hub after first start failed #55

Closed donohoea closed 2 years ago

donohoea commented 2 years ago

Fixes issue #54.

I propose changing this._startSubject.error(error)) to this._errorSubject.next(error)).

The result of calling this._startSubject.error(error)) puts the _startSubject into an error state and further calls to _startSubject.next() will fail silently, while subscribers to `this._startSubject.asObservable()' will immediately receive the error the error and nothing else.

This causes the startHub$ effect:

startHub$ = createEffect(() =>
    this.actions$.pipe(
      ofType(startSignalRHub, reconnectSignalRHub),
      mergeMapHubToAction(({ hub }) => {
        return hub.start().pipe(
          mergeMap((_) => EMPTY),
          catchError((error) =>
            of(signalrError({ hubName: hub.hubName, url: hub.url, error }))
          )
        );
      })
    )
  );

to receive, catch, and then dispatch the error on the next attempt to start the hub even though the connection happens successfully without error.

I haven't experienced the same issues when calling stopHub but I imagine it would make sense to apply the same error handling.