[libcalamares] Expand range of errors for network requests

- All failures were being reported as Timeout, which is confusing
  when they are not. Introduce HttpError for the not-timeout
  other kinds of errors.
- Add operator<< for RequestStatus for nicer error logging.
This commit is contained in:
Adriaan de Groot 2020-05-06 17:50:34 +02:00
parent ea51ff9285
commit 7277d52828
3 changed files with 30 additions and 1 deletions

View File

@ -236,7 +236,7 @@ synchronousRun( QNetworkAccessManager* nam, const QUrl& url, const RequestOption
}
else if ( reply->error() != QNetworkReply::NoError )
{
return qMakePair( RequestStatus( RequestStatus::Timeout ), nullptr );
return qMakePair( RequestStatus( RequestStatus::HttpError ), nullptr );
}
else
{
@ -281,6 +281,30 @@ Manager::asynchronousGet( const QUrl& url, const CalamaresUtils::Network::Reques
return asynchronousRun( d->nam(), url, options );
}
QDebug&
operator<<( QDebug& s, const CalamaresUtils::Network::RequestStatus& e )
{
s << int( e.status ) << bool( e );
switch ( e.status )
{
case RequestStatus::Ok:
break;
case RequestStatus::Timeout:
s << "Timeout";
break;
case RequestStatus::Failed:
s << "Failed";
break;
case RequestStatus::HttpError:
s << "HTTP";
break;
case RequestStatus::Empty:
s << "Empty";
break;
}
return s;
}
} // namespace Network
} // namespace CalamaresUtils

View File

@ -22,6 +22,7 @@
#include "DllMacro.h"
#include <QByteArray>
#include <QDebug>
#include <QObject>
#include <QUrl>
@ -78,6 +79,7 @@ struct RequestStatus
Ok,
Timeout, // Timeout exceeded
Failed, // bad Url
HttpError, // some other HTTP error (eg. SSL failed)
Empty // for ping(), response is empty
};
@ -90,6 +92,8 @@ struct RequestStatus
State status;
};
QDebug& operator<<( QDebug& s, const RequestStatus& e );
class DLLEXPORT Manager : QObject
{
Q_OBJECT

View File

@ -49,5 +49,6 @@ NetworkTests::testPing()
auto& nam = Manager::instance();
auto canPing_www_kde_org
= nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) );
cDebug() << "Ping:" << canPing_www_kde_org;
QVERIFY( canPing_www_kde_org );
}