api.cc: expose error type in requestDone signal (#24064)

* put error in requestDone

* only check in tools
This commit is contained in:
Willem Melching
2022-03-30 12:12:33 +02:00
committed by GitHub
parent 81862fce76
commit 34a8a5ea76
4 changed files with 9 additions and 8 deletions
+2 -5
View File
@@ -117,7 +117,7 @@ void HttpRequest::requestFinished() {
networkTimer->stop();
if (reply->error() == QNetworkReply::NoError) {
emit requestDone(reply->readAll(), true);
emit requestDone(reply->readAll(), true, reply->error());
} else {
QString error;
if (reply->error() == QNetworkReply::OperationCanceledError) {
@@ -125,12 +125,9 @@ void HttpRequest::requestFinished() {
nam()->clearConnectionCache();
error = "Request timed out";
} else {
if (reply->error() == QNetworkReply::ContentAccessDenied || reply->error() == QNetworkReply::AuthenticationRequiredError) {
qWarning() << ">> Unauthorized. Authenticate with tools/lib/auth.py <<";
}
error = reply->errorString();
}
emit requestDone(error, false);
emit requestDone(error, false, reply->error());
}
reply->deleteLater();
+1 -1
View File
@@ -31,7 +31,7 @@ public:
bool timeout() const;
signals:
void requestDone(const QString &response, bool success);
void requestDone(const QString &response, bool success, QNetworkReply::NetworkError error);
protected:
QNetworkReply *reply = nullptr;
+1 -1
View File
@@ -15,7 +15,7 @@ RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, con
if (!cacheKey.isEmpty()) {
prevResp = QString::fromStdString(params.get(cacheKey.toStdString()));
if (!prevResp.isEmpty()) {
QTimer::singleShot(500, [=]() { emit requestDone(prevResp, true); });
QTimer::singleShot(500, [=]() { emit requestDone(prevResp, true, QNetworkReply::NoError); });
}
QObject::connect(this, &HttpRequest::requestDone, [=](const QString &resp, bool success) {
if (success && resp != prevResp) {
+5 -1
View File
@@ -35,7 +35,11 @@ bool Route::load() {
bool Route::loadFromServer() {
QEventLoop loop;
HttpRequest http(nullptr, !Hardware::PC());
QObject::connect(&http, &HttpRequest::requestDone, [&](const QString &json, bool success) {
QObject::connect(&http, &HttpRequest::requestDone, [&](const QString &json, bool success, QNetworkReply::NetworkError error) {
if (error == QNetworkReply::ContentAccessDenied || error == QNetworkReply::AuthenticationRequiredError) {
qWarning() << ">> Unauthorized. Authenticate with tools/lib/auth.py <<";
}
loop.exit(success ? loadFromJson(json) : 0);
});
http.sendRequest("https://api.commadotai.com/v1/route/" + route_.str + "/files");