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

* put error in requestDone

* only check in tools
old-commit-hash: 34a8a5ea76
taco
Willem Melching 3 years ago committed by GitHub
parent 88c178342f
commit 619b88c1f4
  1. 7
      selfdrive/ui/qt/api.cc
  2. 2
      selfdrive/ui/qt/api.h
  3. 2
      selfdrive/ui/qt/request_repeater.cc
  4. 6
      selfdrive/ui/replay/route.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();

@ -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;

@ -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) {

@ -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");

Loading…
Cancel
Save