Files
gotify-android-client/app/src/main/kotlin/com/github/gotify/api/Api.kt
2023-01-23 10:17:04 +01:00

35 lines
842 B
Kotlin

package com.github.gotify.api
import retrofit2.Call
import java.io.IOException
internal object Api {
@Throws(ApiException::class)
fun execute(call: Call<Void>) {
try {
val response = call.execute()
if (!response.isSuccessful) {
throw ApiException(response)
}
} catch (e: IOException) {
throw ApiException(e)
}
}
@Throws(ApiException::class)
fun <T> execute(call: Call<T>): T {
try {
val response = call.execute()
if (response.isSuccessful) {
return response.body() ?: throw ApiException("null response", response)
} else {
throw ApiException(response)
}
} catch (e: IOException) {
throw ApiException(e)
}
}
}