Handle network timeout before any other error

This commit is contained in:
LordGrey 2023-09-04 19:45:28 +02:00
parent 89eb3523c6
commit bc8cecf19c

View File

@ -296,13 +296,11 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
if (error.error != QJsonParseError::NoError)
{
//Received not valid JSON response
//std::cout << "Response: [" << replyData.toStdString() << "]" << std::endl;
response.setError(true);
response.setErrorReason(error.errorString());
}
else
{
//std::cout << "Response: [" << QString(jsonDoc.toJson(QJsonDocument::Compact)).toStdString() << "]" << std::endl;
response.setBody(jsonDoc);
}
}
@ -314,6 +312,13 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
else
{
QString errorReason;
if (reply->error() == QNetworkReply::OperationCanceledError)
{
errorReason = "Network request timeout error";
}
else
{
qDebug() << "httpStatusCode: "<< httpStatusCode;
if (httpStatusCode > 0) {
QString httpReason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
QString advise;
@ -337,17 +342,11 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
errorReason = QString ("[%3 %4] - %5").arg(httpStatusCode).arg(httpReason, advise);
}
else
{
if (reply->error() == QNetworkReply::OperationCanceledError)
{
errorReason = "Network request timeout error";
}
else
{
errorReason = reply->errorString();
}
}
response.setError(true);
response.setErrorReason(errorReason);
}