Trying to fix NPE around these lines.

This commit is contained in:
Vitor Pamplona 2023-02-04 10:41:01 -05:00
parent bbfd060328
commit 2992d9daf0

View File

@ -43,9 +43,13 @@ object ImageUploader {
client.newCall(request).enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
response.use {
val tree = jacksonObjectMapper().readTree(response.body!!.string())
val url = tree.get("data").get("link").asText()
onSuccess(url)
val body = response.body
if (body != null) {
val tree = jacksonObjectMapper().readTree(body.string())
val url = tree?.get("data")?.get("link")?.asText()
if (url != null)
onSuccess(url)
}
}
}