Open oshai opened 5 years ago
@oshai have you found any solutions?
I forked the repo and changed it. Found out that the codebase is about one file so it's pretty straightforward.
How did you change code, can you show it?. I'm a newbie in Kotlin
I wii share it next week.
I changed this line like this:
override fun onResponse(call: Call<T>, response: Response<T>) {
if (response.isSuccessful) {
deferred.complete(response.body()!!)
} else {
deferred.completeExceptionally(RetrofitException("Error ${response.code()} ${response.message()} in ${call.request().method()}: '${call.request().url()}'", HttpException(response)))
}
}
And added this class:
class RetrofitException(private val requestMessage: String ,private val httpException: HttpException): Exception(requestMessage, httpException), CopyableThrowable<RetrofitException> {
override fun createCopy(): RetrofitException {
return RetrofitException(requestMessage, httpException)
}
}
Thanks Did you use try catch to catch errors? I'm using it, but I found it was too lengthy.
Yes, I am using try/catch.
Ok, thank you, I think it will better if we have an error function like in RxAndroid to catch errors :(
Could you find a solution better than try/catch?
I'm using this way https://gist.github.com/soulduse/b832152e42b893581f7736f4524f3dcd What do you think about this code?
thanks @soulduse, your way is very helpful
When an error occurs on
Deferred.await()
the thrown error stacktrace is not showing any indication of the url/method that was actually called:The code that produces it is this:
I am thinking here of a couple of alternatives:
HttpException
CopyableThrowable
as suggested here: https://github.com/Kotlin/kotlinx.coroutines/issues/1109Any other suggestion?