summaryrefslogtreecommitdiff
path: root/community/wkhtmltopdf/0001-fix-spurious-exit-with-code-1-due-to-http-error-1xxx.patch
blob: 0626b7b6487b331e1a6b3f1269d0ff413e549fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
From d6b406d9ec207036af807af2bee2aeb5e33827f0 Mon Sep 17 00:00:00 2001
From: Ashish Kulkarni <kulkarni.ashish@gmail.com>
Date: Mon, 10 Feb 2014 19:33:21 +0530
Subject: [PATCH 1/2] 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/
---
 src/lib/multipageloader.cc |  2 +-
 src/lib/utilities.cc       | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/lib/multipageloader.cc b/src/lib/multipageloader.cc
index 0f4e7f7..d74fa0d 100644
--- a/src/lib/multipageloader.cc
+++ b/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());
diff --git a/src/lib/utilities.cc b/src/lib/utilities.cc
index 639aa32..4238c47 100644
--- a/src/lib/utilities.cc
+++ b/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);
-- 
2.0.0