Presenting better error messages when the image upload fails.

pull/714/head
Vitor Pamplona 2023-12-05 21:46:35 -05:00
rodzic 6662966ab3
commit fce27c3c55
1 zmienionych plików z 10 dodań i 7 usunięć

Wyświetl plik

@ -123,14 +123,17 @@ class ImageUploader(val account: Account?) {
client.newCall(request).enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
try {
check(response.isSuccessful)
response.body.use { body ->
val url = server.parseUrlFromSuccess(body.string(), authorizationToken)
checkNotNull(url) {
"There must be an uploaded image URL in the response"
}
if (response.isSuccessful) {
response.body.use { body ->
val url = server.parseUrlFromSuccess(body.string(), authorizationToken)
checkNotNull(url) {
"There must be an uploaded image URL in the response"
}
onSuccess(url, contentType)
onSuccess(url, contentType)
}
} else {
onError(RuntimeException("Error Uploading image: ${response.code}"))
}
} catch (e: Exception) {
e.printStackTrace()