Skip to content

Instantly share code, notes, and snippets.

@xpepper
Created November 2, 2023 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpepper/cbc3e682eec9c5d1d63bd6365b904c6a to your computer and use it in GitHub Desktop.
Save xpepper/cbc3e682eec9c5d1d63bd6365b904c6a to your computer and use it in GitHub Desktop.
Testing Ktor response validation
import com.casavo.gluglu.core.infrastructure.http.installLoggingConfiguration
import com.casavo.gluglu.core.infrastructure.http.installUserAgentConfiguration
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.request.url
import io.ktor.http.isSuccess
import kotlinx.coroutines.runBlocking
val client = HttpClient {
expectSuccess = true
followRedirects = true
installUserAgentConfiguration()
installLoggingConfiguration("spike")
}
try {
val response = runBlocking {
client.get {
url("https://httpbin.org/status/500")
}
}
when {
response.status.isSuccess() -> println("success!")
response.status.value in 400..500 -> println("failure!")
else -> println(response.status)
}
} catch (e: Exception) {
println(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment