somfytahoma: Improve error logging for failed HTTP calls

The Somfy API does contain some valuable information in the reply
data and the headers.
master
Christian Fetzer 2022-05-28 22:13:21 +02:00
parent 4cf1449524
commit 427d9b6b42
2 changed files with 15 additions and 3 deletions

View File

@ -98,8 +98,8 @@ void IntegrationPluginSomfyTahoma::confirmPairing(ThingPairingInfo *info, const
info->finish(Thing::ThingErrorAuthenticationFailure, QT_TR_NOOP("Failed to activate token."));
});
connect(request, &SomfyTahomaRequest::finished, info, [this, info, username, password, token](const QVariant &result){
qCDebug(dcSomfyTahoma()) << "Got token uuid" << result;
QString requestId = result.toMap()["requestId"].toString();
qCDebug(dcSomfyTahoma()) << "Got token requestId" << requestId;
pluginStorage()->beginGroup(info->thingId().toString());
pluginStorage()->setValue("username", username);

View File

@ -47,7 +47,19 @@ SomfyTahomaRequest::SomfyTahomaRequest(QNetworkReply *reply, QObject *parent) :
connect(reply, &QNetworkReply::finished, this, [this, reply] {
deleteLater();
if (reply->error() != QNetworkReply::NoError) {
qCWarning(dcSomfyTahoma()) << "Request for" << reply->url().path() << "failed:" << reply->errorString();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QVariantMap requestHeaders;
foreach (const QByteArray &rawHeader, reply->request().rawHeaderList()) {
requestHeaders.insert(rawHeader, reply->request().rawHeader(rawHeader));
}
QVariantMap replyHeaders;
foreach (const QByteArray &rawHeader, reply->rawHeaderList()) {
replyHeaders.insert(rawHeader, reply->rawHeader(rawHeader));
}
qCWarning(dcSomfyTahoma()).noquote() << "Request error:" << status << "for URL:" << reply->url().toString()
<< "on operation" << reply->operation() << "\n" << "Content:" << reply->readAll();
qCDebug(dcSomfyTahoma()).noquote() << "Request headers:" << QJsonDocument::fromVariant(requestHeaders).toJson()
<< "Reply headers:" << QJsonDocument::fromVariant(replyHeaders).toJson();
emit error(reply->error());
return;
}
@ -56,7 +68,7 @@ SomfyTahomaRequest::SomfyTahomaRequest(QNetworkReply *reply, QObject *parent) :
QJsonParseError parseError;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &parseError);
if (parseError.error != QJsonParseError::NoError) {
qCWarning(dcSomfyTahoma()) << "Json parse error in reply for" << reply->url().path() << ":" << parseError.errorString();
qCWarning(dcSomfyTahoma()) << "Json parse error:" << reply->url().toString() << ":" << parseError.error << parseError.errorString();
emit error(QNetworkReply::UnknownContentError);
return;
}