throwing clearer error message when not supported 301 response code is used (#6296)

This commit is contained in:
nikinagy 2020-06-01 11:55:17 +01:00 committed by GitHub
parent 9f2bd1dcae
commit 14b9bc2c53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,7 @@ import java.lang.reflect.Member
import java.lang.reflect.Modifier
import java.math.BigDecimal
import java.net.HttpURLConnection
import java.net.HttpURLConnection.HTTP_MOVED_PERM
import java.net.HttpURLConnection.HTTP_OK
import java.net.Proxy
import java.net.URI
@ -478,9 +479,13 @@ fun URL.post(serializedData: OpaqueBytes, vararg properties: Pair<String, String
@DeleteForDJVM
fun HttpURLConnection.checkOkResponse() {
if (responseCode != HTTP_OK) {
if(responseCode == HTTP_MOVED_PERM) {
throw IOException("Response Code $responseCode Moved Permanently cannot be used here. We only accept $HTTP_OK responses.")
} else {
throw IOException("Response Code $responseCode: $errorMessage")
}
}
}
@DeleteForDJVM
val HttpURLConnection.errorMessage: String? get() = errorStream?.let { it.use { it.reader().readText() } }