cafonsomota
06/21/2022, 11:41 AMpublic suspend fun someCall(random: RandomObject): SomeObject = <http://client.post|client.post>(URL) {
setBody(random)
}.body()
Previously, when I called this from:
public suspend fun invokeSomeCall(random: RandomObject, onSuccess: (SomeObject) -> Unit, onFailure: (SomeErrorObject) -> Unit) {
try {
val response = EntityManagerAPI.someCall(random)
coroutineScope {
onSuccess(response)
}
} catch (e: Exception) {
coroutineScope {
onFailure(processException(e))
}
}
}
And the server returns a 403, the deserialization of SomeObject would fail, and I’ll call onFailure. Now, with the new version, onSuccess is called and it’s deserialized with all the default values.
The rules that I’m using for Json on ContentNegotation are:
public val nonStrictJson: Json = Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
}
From my tests if I change isLenient to false, I get the previous behaviour; in any case I’m trying to understand what changed, or what I might be doing wrong?
Is there a better approach here? Perhaps, checking the status code before?Helio
06/21/2022, 11:48 AMexpectSuccess = true.cafonsomota
06/21/2022, 11:52 AM/**
* Terminate [HttpClient.receivePipeline] if status code is not successful (>=300).
*/
public var expectSuccess: Boolean = falsecafonsomota
06/21/2022, 11:54 AMhttps://github.com/ktorio/ktor/pull/2783I wonder how many people will get their apps broken 😅. @Helio was there some guideline that I might have missed during the migration?
Helio
06/21/2022, 11:57 AMHelio
06/21/2022, 11:58 AMcafonsomota
06/21/2022, 12:00 PMHelio
06/21/2022, 12:08 PM