mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Manage github API errors better.
This commit is contained in:
parent
3bf91feffe
commit
1efbabe6bd
1 changed files with 18 additions and 10 deletions
|
@ -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,17 +120,24 @@ class GithubApi2 @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
service.getReleasesNoAuth("cbeust", "kobalt")
|
service.getReleasesNoAuth("cbeust", "kobalt")
|
||||||
}
|
}
|
||||||
val releases = req.execute().body()
|
val ex = req.execute()
|
||||||
if (releases != null) {
|
val errorBody = ex.errorBody()
|
||||||
releases.firstOrNull()?.let {
|
if (errorBody != null) {
|
||||||
try {
|
val jsonError = JsonParser().parse(errorBody.string())
|
||||||
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
warn("Couldn't call Github.getReleases(): $jsonError")
|
||||||
} catch(ex: NoSuchElementException) {
|
|
||||||
throw KobaltException("Couldn't find the latest release")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
warn("Didn't receive any body in the response to GitHub.getReleases()")
|
val releases = ex.body()
|
||||||
|
if (releases != null) {
|
||||||
|
releases.firstOrNull()?.let {
|
||||||
|
try {
|
||||||
|
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
||||||
|
} catch(ex: NoSuchElementException) {
|
||||||
|
throw KobaltException("Couldn't find the latest release")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue