Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error logging in hold streams #661

Open
@d-stolyar

Description

@d-stolyar

Description

Errors in hold streams are not logged

Steps to Reproduce the Issue

Check stackblitz example

this.hold(
  of(null).pipe(switchMap(() => throwError("error"))),
  value => {
    console.log(value);
  }
);

Result in console:

Expected result in console:
error

Solution

Add console.error in hold definition

hold<S>(
  obsOrObsWithSideEffect: Observable<S>,
  sideEffectFn?: (arg: S) => void
): void {
  const sideEffect = obsOrObsWithSideEffect.pipe(catchError(e => {
    console.error(e)
    return EMPTY
  }))
  if (typeof sideEffectFn === 'function') {
    this.effectObservable.nextEffectObservable(
      sideEffect.pipe(tap(sideEffectFn))
    );
    return;
  }
  this.effectObservable.nextEffectObservable(sideEffect);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions