* Add an overloaded version of the Flow#mapError (Java DSL) which does not use a Scala PartialFunction. * Add test verifying mapError matching on parent class * Add to Source, SubSource and SubFlow as well
This commit is contained in:
parent
653d05e7d6
commit
87b94b65fd
5 changed files with 147 additions and 0 deletions
|
|
@ -1847,6 +1847,30 @@ final class Source[Out, Mat](delegate: scaladsl.Source[Out, Mat]) extends Graph[
|
|||
def mapError(pf: PartialFunction[Throwable, Throwable]): javadsl.Source[Out, Mat] =
|
||||
new Source(delegate.mapError(pf))
|
||||
|
||||
/**
|
||||
* While similar to [[recover]] this operator can be used to transform an error signal to a different one *without* logging
|
||||
* it as an error in the process. So in that sense it is NOT exactly equivalent to `recover(t => throw t2)` since recover
|
||||
* would log the `t2` error.
|
||||
*
|
||||
* Since the underlying failure signal onError arrives out-of-band, it might jump over existing elements.
|
||||
* This operator can recover the failure signal, but not the skipped elements, which will be dropped.
|
||||
*
|
||||
* Similarly to [[recover]] throwing an exception inside `mapError` _will_ be logged.
|
||||
*
|
||||
* '''Emits when''' element is available from the upstream or upstream is failed and pf returns an element
|
||||
*
|
||||
* '''Backpressures when''' downstream backpressures
|
||||
*
|
||||
* '''Completes when''' upstream completes or upstream failed with exception pf can handle
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*
|
||||
*/
|
||||
def mapError[E <: Throwable](clazz: Class[E], f: function.Function[E, Throwable]): javadsl.Source[Out, Mat] =
|
||||
mapError {
|
||||
case err if clazz.isInstance(err) => f(clazz.cast(err))
|
||||
}
|
||||
|
||||
/**
|
||||
* RecoverWith allows to switch to alternative Source on flow failure. It will stay in effect after
|
||||
* a failure has been recovered so that each time there is a failure it is fed into the `pf` and a new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue