Skip to content

Commit a645204

Browse files
committed
log bad responses from mojira.dev
1 parent 66dd1d9 commit a645204

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

  • build-logic/src/main/kotlin/dev/isxander/debugify

build-logic/src/main/kotlin/dev/isxander/debugify/MojiraBug.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.google.gson.JsonSyntaxException
55
import org.gradle.api.provider.Property
66
import org.gradle.api.provider.ValueSource
77
import org.gradle.api.provider.ValueSourceParameters
8+
import java.net.HttpURLConnection
89
import java.net.URI
910

1011
data class MojiraBug(
@@ -19,7 +20,17 @@ data class MojiraBug(
1920
fun fetch(bugId: String): MojiraBug? {
2021
try {
2122
val url = "https://mojira.dev/api/v1/issues/$bugId"
22-
val response = URI(url).toURL().readText()
23+
24+
val connection = URI(url).toURL().openConnection() as HttpURLConnection
25+
val statusCode = connection.responseCode
26+
val response = (connection.errorStream ?: connection.inputStream)
27+
.bufferedReader()
28+
.use { it.readText() }
29+
30+
if (statusCode != HttpURLConnection.HTTP_OK) {
31+
throw IllegalStateException("Bad resposne HTTP $statusCode: $response")
32+
}
33+
2334
return try {
2435
Gson().fromJson(response, MojiraBug::class.java)
2536
} catch (e: JsonSyntaxException) {

0 commit comments

Comments
 (0)