Distractic
11/21/2023, 9:47 PMCOMMON HEADERS
-> Cache-Control: no-store
-> Content-Length: 0
-> Content-Type: application/json
-> Date: Tue, 21 Nov 2023 21:40:39 GMT
-> Strict-Transport-Security: max-age=31536000; includeSubDomains
BODY Content-Type: application/json
BODY START
BODY END
The body is empty, so when I try to read it, my code throws an exception and I would like to avoid that.
Do you know how can I check if the response has a body or not ?Berkay Özkan
11/21/2023, 9:49 PMcall.receiveNullable
Distractic
11/21/2023, 9:51 PMHttpResponseValidator {
validateResponse { response ->
if (!response.status.isSuccess()) {
// Get body here
}
}
}
Distractic
11/21/2023, 9:52 PMBerkay Özkan
11/21/2023, 10:06 PMMV
11/21/2023, 10:08 PMsuspend fun getNodeInfo(instance: String): Result<NodeInfo> = runCatching {
lenientKtor
.get("${constructBaseUrl(instance)}/nodeinfo/2.0.json")
.body<NodeInfo>()
}
suspend fun someOther(){
val node = getNodeInfo(instance)
if(node.isSuccess) { ... }
}
Distractic
11/21/2023, 10:18 PMMV
11/21/2023, 10:24 PMWith always a different format so that's a bit annoyingwhat do you mean with that? Do you mean you always get unkown json structure? You can read the body as a generic JsonObject and parse that
Distractic
11/22/2023, 6:24 AM{data:{error: <message>}}
•
{errors: [list of message]}
Aleksei Tirman [JB]
11/22/2023, 9:12 AMDistractic
11/22/2023, 9:15 AMbodyAsText
should returns empty string instead of throw an illegalStateException 🤔Aleksei Tirman [JB]
11/22/2023, 9:16 AMDistractic
11/22/2023, 9:17 AMDistractic
11/22/2023, 9:24 AM