Include more error messaging for failed image uploads (#4096)

This commit is contained in:
pajlada 2022-11-01 21:39:26 +01:00 committed by GitHub
parent a033dbc933
commit abb69f6794
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -204,9 +204,32 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel,
return Success; return Success;
}) })
.onError([channel](NetworkResult result) -> bool { .onError([channel](NetworkResult result) -> bool {
channel->addMessage(makeSystemMessage( auto errorMessage =
QString("An error happened while uploading your image: %1") QString("An error happened while uploading your image: %1")
.arg(result.status()))); .arg(result.status());
// Try to read more information from the result body
auto obj = result.parseJson();
if (!obj.isEmpty())
{
auto apiCode = obj.value("code");
if (!apiCode.isUndefined())
{
auto codeString = apiCode.toVariant().toString();
codeString.truncate(20);
errorMessage += QString(" - code: %1").arg(codeString);
}
auto apiError = obj.value("error").toString();
if (!apiError.isEmpty())
{
apiError.truncate(300);
errorMessage +=
QString(" - error: %1").arg(apiError.trimmed());
}
}
channel->addMessage(makeSystemMessage(errorMessage));
uploadMutex.unlock(); uploadMutex.unlock();
return true; return true;
}) })