1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Manage github API errors better.

This commit is contained in:
Cedric Beust 2017-01-11 15:03:16 -08:00
parent 3bf91feffe
commit 1efbabe6bd

View file

@ -6,6 +6,7 @@ import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.maven.Http import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.aether.Exceptions import com.beust.kobalt.maven.aether.Exceptions
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonParser
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import com.google.inject.Inject import com.google.inject.Inject
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
@ -119,7 +120,13 @@ class GithubApi2 @Inject constructor(
} else { } else {
service.getReleasesNoAuth("cbeust", "kobalt") service.getReleasesNoAuth("cbeust", "kobalt")
} }
val releases = req.execute().body() val ex = req.execute()
val errorBody = ex.errorBody()
if (errorBody != null) {
val jsonError = JsonParser().parse(errorBody.string())
warn("Couldn't call Github.getReleases(): $jsonError")
} else {
val releases = ex.body()
if (releases != null) { if (releases != null) {
releases.firstOrNull()?.let { releases.firstOrNull()?.let {
try { try {
@ -131,6 +138,7 @@ class GithubApi2 @Inject constructor(
} else { } else {
warn("Didn't receive any body in the response to GitHub.getReleases()") warn("Didn't receive any body in the response to GitHub.getReleases()")
} }
}
} catch(e: Exception) { } catch(e: Exception) {
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message) kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
Exceptions.printStackTrace(e) Exceptions.printStackTrace(e)