mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Include more error messaging for failed image uploads (#4096)
This commit is contained in:
parent
a033dbc933
commit
abb69f6794
1 changed files with 25 additions and 2 deletions
|
@ -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;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue