`fun <R> Observable<R>.mapErrors(): Ob...
# codereview
m
fun <R> Observable<R>.mapErrors(): Observable<R> {
return this.onErrorResumeNext { t: Throwable ->
val error = when (t) {
is UnknownHostException -> NoInternetException
else -> t
}
Observable.error(error)
}
}
f
@Mohamed Ibrahim Why do you need
when
statement? In this case, it can be done with
if-else
.
m
I could add more Errors types
f
you can create a
ErrorFactory
to transform errors into your exceptions. Then, call it by
Copy code
val error = errorFactory.create(throwable)
return Observable.error(error)
You can extend your error factory by handling more exceptions.
2