18 #include "QMessageBox"
22 QmitkHttpStatusCodeHandler::QmitkHttpStatusCodeHandler()
26 QmitkHttpStatusCodeHandler::~QmitkHttpStatusCodeHandler()
38 QMessageBox::warning(
nullptr,
39 "ConnectionRefusedError - 1",
40 "The remote server refused the connection (the server is not accepting requests).");
45 "RemoteHostClosedError - 2",
46 "The remote server closed the connection prematurely, before the entire reply was received and processed.");
49 QMessageBox::warning(
nullptr,
"HostNotFoundError - 3",
"The remote host name was not found (invalid hostname).");
52 QMessageBox::warning(
nullptr,
"TimeoutError - 4",
"The connection to the remote server timed out.");
55 QMessageBox::warning(
nullptr,
56 "OperationCanceledError - 5",
57 "The operation was canceled via calls to abort() or close() before it was finished.");
60 QMessageBox::warning(
nullptr,
"SslHandshakeFailedError - 6",
"The SSL/TLS handshake failed and the encrypted "
61 "channel could not be established. The sslErrors() "
62 "signal should have been emitted.");
65 QMessageBox::warning(
nullptr,
66 "TemporaryNetworkFailureError - 7",
67 "The connection was broken due to disconnection from the network, however the system has "
68 "initiated roaming to another access point. The request should be resubmitted and will be "
69 "processed as soon as the connection is re-established.");
74 "NetworkSessionFailedError - 8",
75 "The connection was broken due to disconnection from the network or failure to start the network.");
78 QMessageBox::warning(
nullptr,
79 "BackgroundRequestNotAllowedError - 9",
80 "The background request is not currently allowed due to platform policy.");
83 QMessageBox::warning(
nullptr,
"TooManyRedirectsError - 10 ",
"While following redirects, the maximum limit was "
84 "reached. The limit is by default set to 50 or as "
85 "set by QNetworkRequest::setMaxRedirectsAllowed().");
88 QMessageBox::warning(
nullptr,
"InsecureRedirectError - 11 ",
"While following redirects, the network access API "
89 "detected a redirect from a encrypted protocol "
90 "(https) to an unencrypted one (http).");
95 "ProxyConnectionRefusedError - 101",
96 "The connection to the proxy server was refused (the proxy server is not accepting requests).");
101 "ProxyConnectionClosedError - 102",
102 "The proxy server closed the connection prematurely, before the entire reply was received and processed.");
105 QMessageBox::warning(
106 nullptr,
"ProxyNotFoundError - 103",
"The proxy host name was not found (invalid proxy hostname).");
109 QMessageBox::warning(
111 "ProxyTimeoutError - 104",
112 "The connection to the proxy timed out or the proxy did not reply in time to the request sent.");
115 QMessageBox::warning(
nullptr,
"ProxyAuthenticationRequiredError - 105",
"The proxy requires authentication in "
116 "order to honour the request but did not "
117 "accept any credentials offered (if "
121 QMessageBox::warning(
nullptr,
122 "ContentAccessDenied - 201",
123 "The access to the remote content was denied (similar to HTTP error 401).");
126 QMessageBox::warning(
nullptr,
127 "ContentOperationNotPermittedError - 202",
128 "The operation requested on the remote content is not permitted.");
131 QMessageBox::warning(
nullptr,
132 "ContentNotFoundError - 203",
133 "The remote content was not found at the server (similar to HTTP error 404).");
136 QMessageBox::warning(
nullptr,
"AuthenticationRequiredError - 204",
"The remote server requires authentication to "
137 "serve the content but the credentials "
138 "provided were not accepted (if any).");
141 QMessageBox::warning(
nullptr,
"ContentReSendError - 205",
"The request needed to be sent again, but this failed "
142 "for example because the upload data could not be read "
146 QMessageBox::warning(
148 "ContentConflictError - 206",
149 "The request could not be completed due to a conflict with the current state of the resource.");
152 QMessageBox::warning(
153 nullptr,
"ContentGoneError - 207",
"The requested resource is no longer available at the server.");
156 QMessageBox::warning(
158 "InternalServerError - 401",
159 "The server encountered an unexpected condition which prevented it from fulfilling the request.");
162 QMessageBox::warning(
nullptr,
163 "OperationNotImplementedError - 402",
164 "The server does not support the functionality required to fulfill the request.");
167 QMessageBox::warning(
168 nullptr,
"ServiceUnavailableError - 403",
"The server is unable to handle the request at this time.");
171 QMessageBox::warning(
nullptr,
172 "ProtocolUnknownError - 301",
173 "The Network Access API cannot honor the request because the protocol is not known.");
176 QMessageBox::warning(
177 nullptr,
"ProtocolInvalidOperationError - 302",
"The requested operation is invalid for this protocol.");
180 QMessageBox::warning(
nullptr,
"UnknownNetworkError - 99",
"An unknown network-related error was detected.");
183 QMessageBox::warning(
nullptr,
"UnknownProxyError - 199",
"An unknown proxy-related error was detected.");
186 QMessageBox::warning(
187 nullptr,
"UnknownContentError - 299",
"An unknown error related to the remote content was detected.");
190 QMessageBox::warning(
192 "ProtocolFailure - 399",
193 "A breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.).");
196 QMessageBox::warning(
197 nullptr,
"UnknownServerError - 499",
"An unknown error related to the server response was detected.");
200 ss <<
"An Http Error occured with error code " << statusCode <<
" and server message: " << errorMessage;
201 QMessageBox::warning(
nullptr,
"HTTP ERROR", ss.str().c_str());
208 static int lastCode = 0;
209 std::string errorMsg(_errorMsg, strnlen(_errorMsg, strlen(_errorMsg)));
218 if (errorMsg.find(
"request failed.") == std::string::npos)
221 std::string::size_type indexOfErrorCode = errorMsg.find(
": Error") - 3;
222 std::string::size_type indexOfServerResponse =
223 errorMsg.rfind(
"server replied: ") + 16;
225 if (indexOfErrorCode == std::string::npos || indexOfServerResponse == std::string::npos)
228 std::string statusCodeString = errorMsg.substr(indexOfErrorCode, 3);
229 std::stringstream str;
230 str << statusCodeString;
234 std::string serverResponse = errorMsg.substr(indexOfServerResponse);
236 if (lastCode != statusCode)
239 if (!success && lastCode != statusCode)
241 QMessageBox::warning(
nullptr,
"General Error", errorMsg.c_str());
244 if (lastCode != statusCode)
245 lastCode = statusCode;
static void CreateMessageBox(int statusCode, std::string errorMessage)
static bool HandleErrorMessage(const char *_errorMsg)