Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EventStream.mapError #78

Open
ajaychandran opened this issue Apr 6, 2021 · 4 comments
Open

Add EventStream.mapError #78

ajaychandran opened this issue Apr 6, 2021 · 4 comments

Comments

@ajaychandran
Copy link
Contributor

This can be implemented using:

final class MapErrorEventStream[A](val parent: Observable[A], f: PartialFunction[Throwable, Throwable])
    extends EventStream[A]
    with SingleParentObservable[A, A]
    with InternalNextErrorObserver[A] {

  protected[airstream] val topoRank: Int = parent.topoRank + 1

  protected[airstream] def onNext(nextValue: A, transaction: Transaction): Unit =
    fireValue(nextValue, transaction)

  protected[airstream] def onError(nextError: Throwable, transaction: Transaction): Unit =
    try fireError(f.applyOrElse(nextError, identity[Throwable]), transaction)
    catch { case NonFatal(t) => fireError(AirstreamError.ObserverErrorHandlingError(t, nextError), transaction) }
}

This is useful when using Ajax streams with services that can return specific errors.

@raquo
Copy link
Owner

raquo commented May 2, 2021

mapError would need to accept a total function. I guess we can call this collectError.

@ajaychandran
Copy link
Contributor Author

+1 on total function (since it would support both mapError and collectError).

@raquo
Copy link
Owner

raquo commented May 2, 2021 via email

@ajaychandran
Copy link
Contributor Author

I meant both combinators can be provided.

def mapError(f: Throwable => Throwable)
def collectError(pf: PartialFunction[Throwable, Throwable]) = mapError(pf.applyOrElse(_, identity[Throwable]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants