瀏覽代碼

fix spurious "exit with code 1 due to http error: 1xxx" errors

This fixes #1502 and was introduced in ce6d6cd0f0f86a5b1ff3765aaae357dfdf3be803,
which returned errors above 1000 as a proxy for network errors. However, the
error 5 (i.e. OperationCanceledError) was not handled, which apparently happens
a lot due to parallel loading of resources. We thus ignore this error in the
loader.

In addition, in case the error is greater than 1000, we find out the correct
network error and display that error instead of HTTP error 1xxx which doesn't
exist. The trick to find out the text values for the enum was taken from:

https://blog.qt.digia.com/blog/2008/10/09/coding-tip-pretty-printing-enum-values/
Ashish Kulkarni 11 年之前
父節點
當前提交
efbc7235c4
共有 2 個文件被更改,包括 18 次插入2 次删除
  1. 1 1
      src/lib/multipageloader.cc
  2. 17 1
      src/lib/utilities.cc

+ 1 - 1
src/lib/multipageloader.cc

@@ -335,7 +335,7 @@ void ResourceObject::error(const QString & str) {
 void ResourceObject::amfinished(QNetworkReply * reply) {
 	int networkStatus = reply->error();
 	int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
-	if (networkStatus > 0 || (httpStatus > 399 && httpErrorCode == 0))
+	if ((networkStatus != 0 && networkStatus != 5) || (httpStatus > 399 && httpErrorCode == 0))
 	{
 		QFileInfo fi(reply->url().toString());
 		bool mediaFile = settings::LoadPage::mediaFilesExtensions.contains(fi.completeSuffix().toLower());

+ 17 - 1
src/lib/utilities.cc

@@ -27,6 +27,8 @@
 #include "utilities.hh"
 #include <QDebug>
 #include <QTextStream>
+#include <QMetaEnum>
+#include <QNetworkReply>
 
 void loadSvg(QSvgRenderer * & ptr, const QString & path, const char * def, int w, int h) {
 	 delete ptr;
@@ -160,7 +162,21 @@ int handleError(bool success, int errorCode) {
 		if (ce.contains(errorCode)) c = ce[errorCode];
 		const char * m = "";
 		if (cm.contains(errorCode)) m = cm[errorCode];
-		fprintf(stderr, "Exit with code %d due to http error: %d %s\n", c, errorCode, m);
+		if (errorCode < 1000) {
+			fprintf(stderr, "Exit with code %d due to http error: %d %s\n", c, errorCode, m);
+		} else {
+			QNetworkReply::NetworkError error = (QNetworkReply::NetworkError)(errorCode - 1000);
+			QString errorValue;
+			QMetaObject meta = QNetworkReply::staticMetaObject;
+			for (int i=0; i < meta.enumeratorCount(); ++i) {
+				QMetaEnum m = meta.enumerator(i);
+				if (m.name() == QLatin1String("NetworkError")) {
+					errorValue = QLatin1String(m.valueToKey(error));
+					break;
+				}
+			}
+			fprintf(stderr, "Exit with code %d due to network error: %s\n", c, errorValue.toLocal8Bit().data());
+		}
 		return c;
 	} else if (!success) {
 		fprintf(stderr, "Exit with code %d, due to unknown error.\n", EXIT_FAILURE);