retrofit
retrofit copied to clipboard
How to get the URL endpoint and the GET/POST method when an Exception occurs?
trafficstars
Hello everyone, I need help with an issue.
I use a suspend function to call the API as shown in the code below. How can I get the URL endpoint and the GET/POST method when an Exception occurs?
suspend fun <T : BaseResponse> safeCallApi(
api: suspend () -> Response<T>
): Result<T> {
return try {
val response = api()
if (response.isSuccessful) {
val body = response.body()
if (body != null) {
Result.success(body)
} else {
Result.failure(BodyNullException())
}
} else {
Result.failure(ServerException())
}
} catch (e: Exception) {
// I want to obtain the information about the URL endpoint and the GET/POST method there.
Result.failure(UnknownException(e))
}
}