14 #include "QMessageBox" 18 QmitkHttpStatusCodeHandler::QmitkHttpStatusCodeHandler()
22 QmitkHttpStatusCodeHandler::~QmitkHttpStatusCodeHandler()
34 QMessageBox::warning(
nullptr,
35 "ConnectionRefusedError - 1",
36 "The remote server refused the connection (the server is not accepting requests).");
41 "RemoteHostClosedError - 2",
42 "The remote server closed the connection prematurely, before the entire reply was received and processed.");
45 QMessageBox::warning(
nullptr,
"HostNotFoundError - 3",
"The remote host name was not found (invalid hostname).");
48 QMessageBox::warning(
nullptr,
"TimeoutError - 4",
"The connection to the remote server timed out.");
51 QMessageBox::warning(
nullptr,
52 "OperationCanceledError - 5",
53 "The operation was canceled via calls to abort() or close() before it was finished.");
56 QMessageBox::warning(
nullptr,
"SslHandshakeFailedError - 6",
"The SSL/TLS handshake failed and the encrypted " 57 "channel could not be established. The sslErrors() " 58 "signal should have been emitted.");
61 QMessageBox::warning(
nullptr,
62 "TemporaryNetworkFailureError - 7",
63 "The connection was broken due to disconnection from the network, however the system has " 64 "initiated roaming to another access point. The request should be resubmitted and will be " 65 "processed as soon as the connection is re-established.");
70 "NetworkSessionFailedError - 8",
71 "The connection was broken due to disconnection from the network or failure to start the network.");
74 QMessageBox::warning(
nullptr,
75 "BackgroundRequestNotAllowedError - 9",
76 "The background request is not currently allowed due to platform policy.");
79 QMessageBox::warning(
nullptr,
"TooManyRedirectsError - 10 ",
"While following redirects, the maximum limit was " 80 "reached. The limit is by default set to 50 or as " 81 "set by QNetworkRequest::setMaxRedirectsAllowed().");
84 QMessageBox::warning(
nullptr,
"InsecureRedirectError - 11 ",
"While following redirects, the network access API " 85 "detected a redirect from a encrypted protocol " 86 "(https) to an unencrypted one (http).");
91 "ProxyConnectionRefusedError - 101",
92 "The connection to the proxy server was refused (the proxy server is not accepting requests).");
97 "ProxyConnectionClosedError - 102",
98 "The proxy server closed the connection prematurely, before the entire reply was received and processed.");
101 QMessageBox::warning(
102 nullptr,
"ProxyNotFoundError - 103",
"The proxy host name was not found (invalid proxy hostname).");
105 QMessageBox::warning(
107 "ProxyTimeoutError - 104",
108 "The connection to the proxy timed out or the proxy did not reply in time to the request sent.");
111 QMessageBox::warning(
nullptr,
"ProxyAuthenticationRequiredError - 105",
"The proxy requires authentication in " 112 "order to honour the request but did not " 113 "accept any credentials offered (if " 117 QMessageBox::warning(
nullptr,
118 "ContentAccessDenied - 201",
119 "The access to the remote content was denied (similar to HTTP error 401).");
122 QMessageBox::warning(
nullptr,
123 "ContentOperationNotPermittedError - 202",
124 "The operation requested on the remote content is not permitted.");
127 QMessageBox::warning(
nullptr,
128 "ContentNotFoundError - 203",
129 "The remote content was not found at the server (similar to HTTP error 404).");
132 QMessageBox::warning(
nullptr,
"AuthenticationRequiredError - 204",
"The remote server requires authentication to " 133 "serve the content but the credentials " 134 "provided were not accepted (if any).");
137 QMessageBox::warning(
nullptr,
"ContentReSendError - 205",
"The request needed to be sent again, but this failed " 138 "for example because the upload data could not be read " 142 QMessageBox::warning(
144 "ContentConflictError - 206",
145 "The request could not be completed due to a conflict with the current state of the resource.");
148 QMessageBox::warning(
149 nullptr,
"ContentGoneError - 207",
"The requested resource is no longer available at the server.");
152 QMessageBox::warning(
154 "InternalServerError - 401",
155 "The server encountered an unexpected condition which prevented it from fulfilling the request.");
158 QMessageBox::warning(
nullptr,
159 "OperationNotImplementedError - 402",
160 "The server does not support the functionality required to fulfill the request.");
163 QMessageBox::warning(
164 nullptr,
"ServiceUnavailableError - 403",
"The server is unable to handle the request at this time.");
167 QMessageBox::warning(
nullptr,
168 "ProtocolUnknownError - 301",
169 "The Network Access API cannot honor the request because the protocol is not known.");
172 QMessageBox::warning(
173 nullptr,
"ProtocolInvalidOperationError - 302",
"The requested operation is invalid for this protocol.");
176 QMessageBox::warning(
nullptr,
"UnknownNetworkError - 99",
"An unknown network-related error was detected.");
179 QMessageBox::warning(
nullptr,
"UnknownProxyError - 199",
"An unknown proxy-related error was detected.");
182 QMessageBox::warning(
183 nullptr,
"UnknownContentError - 299",
"An unknown error related to the remote content was detected.");
186 QMessageBox::warning(
188 "ProtocolFailure - 399",
189 "A breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.).");
192 QMessageBox::warning(
193 nullptr,
"UnknownServerError - 499",
"An unknown error related to the server response was detected.");
196 ss <<
"An Http Error occured with error code " << statusCode <<
" and server message: " << errorMessage;
197 QMessageBox::warning(
nullptr,
"HTTP ERROR", ss.str().c_str());
204 static int lastCode = 0;
205 std::string errorMsg(_errorMsg, strnlen(_errorMsg, strlen(_errorMsg)));
214 if (errorMsg.find(
"request failed.") == std::string::npos)
217 std::string::size_type indexOfErrorCode = errorMsg.find(
": Error") - 3;
218 std::string::size_type indexOfServerResponse =
219 errorMsg.rfind(
"server replied: ") + 16;
221 if (indexOfErrorCode == std::string::npos || indexOfServerResponse == std::string::npos)
224 std::string statusCodeString = errorMsg.substr(indexOfErrorCode, 3);
225 std::stringstream str;
226 str << statusCodeString;
230 std::string serverResponse = errorMsg.substr(indexOfServerResponse);
232 if (lastCode != statusCode)
235 if (!success && lastCode != statusCode)
237 QMessageBox::warning(
nullptr,
"General Error", errorMsg.c_str());
240 if (lastCode != statusCode)
241 lastCode = statusCode;
static void CreateMessageBox(int statusCode, std::string errorMessage)
static bool HandleErrorMessage(const char *_errorMsg)