Closed DivineDominion closed 5 years ago
Hi @DivineDominion thank you for contribution!
I think it's not generic enough to be included in RxSwiftExt. Moreover, I would say that using Result
instead of raw events is not very good idea, because you are actually breaking the contract.
RxSwift best practice - use builtin error system and follow the contract. You can read more about it here - https://github.com/ReactiveX/RxSwift/issues/729
I don't know if it's a good idea or not to use Result, but I agree with Anton that it's not a common enough use case to add into RxSwiftExt IMHO. If you could gather some substantial community interest around this, we can explore this further :) Thanks!
Closed due to lack of arguments for adding this
Name and description
Operator signature:
Tries to cast
Event.error
toResult.Failure
and emits the event as.next(.failure(...))
instead of exiting the sequence with an error. If the cast fails, continue with whatever error event happened.Implementation
Motivation for inclusion
The RxSwift docs on Traits provide HTTP requests an an example for
Single<Value>
. If you produce.error
for failed requests, this will end any related observable sequence with error as well; you need to recover from errors in this case:Usually, you'll want to retry, catch errors and alert the user, or otherwise recover from the situation. You don't want the whole wiring to fall apart.
Since
Single<Value>
is so close toResult<Success, Failure>
, I figured that expected errors can be mapped toResult.failure
s. This works when your HTTP API produces 1 error type.Example of use
The motivation example above, transformed to