From 619b88c1f4d9ec0f162438d0a52494e61ed27d77 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Wed, 30 Mar 2022 12:12:33 +0200 Subject: [PATCH] api.cc: expose error type in requestDone signal (#24064) * put error in requestDone * only check in tools old-commit-hash: 34a8a5ea76d05432ee24f5d2a2307b74ad755971 --- selfdrive/ui/qt/api.cc | 7 ++----- selfdrive/ui/qt/api.h | 2 +- selfdrive/ui/qt/request_repeater.cc | 2 +- selfdrive/ui/replay/route.cc | 6 +++++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index 8ac9b41313..79e9506598 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -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(); diff --git a/selfdrive/ui/qt/api.h b/selfdrive/ui/qt/api.h index 8f74678109..5963d1cf44 100644 --- a/selfdrive/ui/qt/api.h +++ b/selfdrive/ui/qt/api.h @@ -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; diff --git a/selfdrive/ui/qt/request_repeater.cc b/selfdrive/ui/qt/request_repeater.cc index 7ef1c833ab..fa37c015f7 100644 --- a/selfdrive/ui/qt/request_repeater.cc +++ b/selfdrive/ui/qt/request_repeater.cc @@ -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) { diff --git a/selfdrive/ui/replay/route.cc b/selfdrive/ui/replay/route.cc index 509be15383..d5e05a0837 100644 --- a/selfdrive/ui/replay/route.cc +++ b/selfdrive/ui/replay/route.cc @@ -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");