mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 16:26:14 +08:00
api.cc: expose error type in requestDone signal (#24064)
* put error in requestDone * only check in tools
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user