File tree Expand file tree Collapse file tree
build-logic/src/main/kotlin/dev/isxander/debugify Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import com.google.gson.JsonSyntaxException
55import org.gradle.api.provider.Property
66import org.gradle.api.provider.ValueSource
77import org.gradle.api.provider.ValueSourceParameters
8+ import java.net.HttpURLConnection
89import java.net.URI
910
1011data 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 ) {
You can’t perform that action at this time.
0 commit comments