https://kotlinlang.org logo
Title
h

Hamza

06/08/2020, 2:21 PM
https://api.ktor.io/1.3.2/io.ktor.client.statement/read-text.html How come this responds with an error if the response code is not 200?
HttpClient().use { client ->
 val response = client.submitForm<HttpResponse>(
  url = "<https://discord.com/api/oauth2/token>",
  formParameters = Parameters.build {
   append("client_id", config.discord.client)
   append("client_secret", config.discord.secret)
   append("grant_type", "authorization_code")
   append("redirect_uri", config.discord.redirect)
   append("scope", "identify")
   append("code", code)
  })
  println(response.readText()) // throws an error if response status is not 200.
}
a

andev

06/08/2020, 2:27 PM
set expectSuccess to false
h

Hamza

06/08/2020, 2:28 PM
👍
a

andev

06/08/2020, 2:29 PM
val client = HttpClient{
        expectSuccess = false
    }
h

Hamza

06/08/2020, 2:31 PM
yep 😄