https://kotlinlang.org logo
#codereview
Title
# codereview
m

Mohamed Ibrahim

10/17/2019, 8:00 AM
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

furkan.akdemir

10/17/2019, 12:01 PM
@Mohamed Ibrahim Why do you need
when
statement? In this case, it can be done with
if-else
.
m

Mohamed Ibrahim

10/17/2019, 12:18 PM
I could add more Errors types
f

furkan.akdemir

10/18/2019, 9:17 AM
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
5 Views