Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114904
D104.1732590939.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D104.1732590939.diff
View Options
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
@@ -7,6 +7,7 @@
#include <kazv-defs.hpp>
#include "kazv-io-job.hpp"
#include "matrix-room.hpp"
+#include "kazv-log.hpp"
#include <QObject>
#include <QPointer>
@@ -16,6 +17,7 @@
#include <QString>
#include <QMimeDatabase>
#include <QCryptographicHash>
+#include <QLoggingCategory>
#include <KJob>
#include <KIO/TransferJob>
@@ -295,9 +297,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);
+ qCWarning(kazvLog) << "Get a invaild response from server.";
+ return;
+ }
+ QString mxcUri{};
+ if (j.contains("content_uri") && j["content_uri"].is_string()) {
+ mxcUri = QString::fromStdString(j["content_uri"].template get<std::string>());
+ } else {
+ emitResult(ResponseError);
+ qCWarning(kazvLog) << "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/cmn-Hans/100-ui.ftl b/src/l10n/cmn-Hans/100-ui.ftl
--- a/src/l10n/cmn-Hans/100-ui.ftl
+++ b/src/l10n/cmn-Hans/100-ui.ftl
@@ -197,6 +197,7 @@
kazv-io-failure-detail-open-file-error = 打开文件错误
kazv-io-failure-detail-write-file-error = 写入文件错误
kazv-io-failure-detail-hash-error = 哈息值校验失败
+kazv-io-failure-detail-response-error = 接收到无效的响应
kazv-io-failure-detail-kazv-error = 未知错误,请将此报告为漏洞
kazv-io-upload-failure-prompt = 上传失败:{ $detail }
kazv-io-downloading-prompt = 正在下载:{ $fileName }
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
@@ -212,6 +212,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
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 7:15 PM (12 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39510
Default Alt Text
D104.1732590939.diff (3 KB)
Attached To
Mode
D104: Fix crash when upload failed
Attached
Detach File
Event Timeline
Log In to Comment