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))
}
}
New contributor
vstung is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.