[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:
parent
ea51ff9285
commit
7277d52828
@ -236,7 +236,7 @@ synchronousRun( QNetworkAccessManager* nam, const QUrl& url, const RequestOption
|
|||||||
}
|
}
|
||||||
else if ( reply->error() != QNetworkReply::NoError )
|
else if ( reply->error() != QNetworkReply::NoError )
|
||||||
{
|
{
|
||||||
return qMakePair( RequestStatus( RequestStatus::Timeout ), nullptr );
|
return qMakePair( RequestStatus( RequestStatus::HttpError ), nullptr );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -281,6 +281,30 @@ Manager::asynchronousGet( const QUrl& url, const CalamaresUtils::Network::Reques
|
|||||||
return asynchronousRun( d->nam(), url, options );
|
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 Network
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
|
#include <QDebug>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ struct RequestStatus
|
|||||||
Ok,
|
Ok,
|
||||||
Timeout, // Timeout exceeded
|
Timeout, // Timeout exceeded
|
||||||
Failed, // bad Url
|
Failed, // bad Url
|
||||||
|
HttpError, // some other HTTP error (eg. SSL failed)
|
||||||
Empty // for ping(), response is empty
|
Empty // for ping(), response is empty
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -90,6 +92,8 @@ struct RequestStatus
|
|||||||
State status;
|
State status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QDebug& operator<<( QDebug& s, const RequestStatus& e );
|
||||||
|
|
||||||
class DLLEXPORT Manager : QObject
|
class DLLEXPORT Manager : QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -49,5 +49,6 @@ NetworkTests::testPing()
|
|||||||
auto& nam = Manager::instance();
|
auto& nam = Manager::instance();
|
||||||
auto canPing_www_kde_org
|
auto canPing_www_kde_org
|
||||||
= nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) );
|
= nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) );
|
||||||
|
cDebug() << "Ping:" << canPing_www_kde_org;
|
||||||
QVERIFY( canPing_www_kde_org );
|
QVERIFY( canPing_www_kde_org );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user