Page MenuHomePhorge

D104.1732309210.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D104.1732309210.diff

diff --git a/src/contents/ui/KazvIOMenu.qml b/src/contents/ui/KazvIOMenu.qml
--- a/src/contents/ui/KazvIOMenu.qml
+++ b/src/contents/ui/KazvIOMenu.qml
@@ -57,6 +57,7 @@
[MK.KazvIOBaseJob.WriteFileError, 'kazv-io-failure-detail-write-file-error'],
[MK.KazvIOBaseJob.KIOError, 'kazv-io-failure-detail-network-error'],
[MK.KazvIOBaseJob.HashError, 'kazv-io-failure-detail-hash-error'],
+ [MK.KazvIOBaseJob.ResponseError, 'kazv-io-failure-detail-response-error'],
[MK.KazvIOBaseJob.KazvError, 'kazv-io-failure-detail-kazv-error']
])
resultMsg.text = l10n.get(resultL10nId, {detail: l10n.get(detailL10nId.get(ec))})
diff --git a/src/kazv-io-job.hpp b/src/kazv-io-job.hpp
--- a/src/kazv-io-job.hpp
+++ b/src/kazv-io-job.hpp
@@ -58,6 +58,11 @@
* Error caused by hash error
*/
HashError,
+ /**
+ * Error caused by invalid response.
+ * KIO reported no error, but got an invalid JSON response.
+ */
+ ResponseError,
/**
* Errors caused by bad code, means the bug is somewhere.
*/
diff --git a/src/kazv-io-job.cpp b/src/kazv-io-job.cpp
--- a/src/kazv-io-job.cpp
+++ b/src/kazv-io-job.cpp
@@ -295,9 +295,22 @@
return;
}
- auto j = nlohmann::json::parse(m_d->response.toStdString());
- auto mxcUri = QString::fromStdString(j["content_uri"].get<std::string>());
-
+ nlohmann::json j{};
+ try {
+ j = nlohmann::json::parse(m_d->response.toStdString());
+ } catch(...) {
+ emitResult(ResponseError);
+ qDebug() << "Get a invaild response from server.";
+ return;
+ }
+ QString mxcUri{};
+ if (j.contains("content_uri")) {
+ mxcUri = QString::fromStdString(j["content_uri"].get<std::string>());
+ } else {
+ emitResult(ResponseError);
+ qDebug() << "There is no \"content_uri\" field in response.";
+ return;
+ }
auto shouldSendMessage = !!m_d->room;
if (shouldSendMessage) {
auto aes = this->aes();
diff --git a/src/l10n/en/100-ui.ftl b/src/l10n/en/100-ui.ftl
--- a/src/l10n/en/100-ui.ftl
+++ b/src/l10n/en/100-ui.ftl
@@ -209,6 +209,7 @@
kazv-io-failure-detail-open-file-error = Open file error
kazv-io-failure-detail-write-file-error = Write file error
kazv-io-failure-detail-hash-error = Hash check error
+kazv-io-failure-detail-response-error = Get an invalid response
kazv-io-failure-detail-kazv-error = Unknow Error, please report this as bug.
kazv-io-upload-failure-prompt = Upload failure: { $detail }
kazv-io-downloading-prompt = Downloading: { $fileName }

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 1:00 PM (4 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38982
Default Alt Text
D104.1732309210.diff (2 KB)

Event Timeline