Modernize extractErrorMessage and AbstractNetworkJob::errorStringParsingBody.

- Add const auto.
- Remove extra error message information to make it more user friendly.

Signed-off-by: Camila Ayres <hello@camilasan.com>
This commit is contained in:
Camila Ayres 2024-02-02 11:31:21 +01:00
parent 6d50b87587
commit b3b48dc163

View file

@ -323,20 +323,20 @@ QString AbstractNetworkJob::errorString() const
QString AbstractNetworkJob::errorStringParsingBody(QByteArray *body) QString AbstractNetworkJob::errorStringParsingBody(QByteArray *body)
{ {
QString base = errorString(); const auto base = errorString();
if (base.isEmpty() || !reply()) { if (base.isEmpty() || !reply()) {
return QString(); return QString();
} }
QByteArray replyBody = reply()->readAll(); const auto replyBody = reply()->readAll();
if (body) { if (body) {
*body = replyBody; *body = replyBody;
} }
QString extra = extractErrorMessage(replyBody); const auto extra = extractErrorMessage(replyBody);
// Don't append the XML error message to a OC-ErrorString message. // Don't append the XML error message to a OC-ErrorString message.
if (!extra.isEmpty() && !reply()->hasRawHeader("OC-ErrorString")) { if (!extra.isEmpty() && !reply()->hasRawHeader("OC-ErrorString")) {
return QString::fromLatin1("%1 (%2)").arg(base, extra); return extra;
} }
return base; return base;
@ -416,7 +416,7 @@ QString extractErrorMessage(const QByteArray &errorResponse)
while (!reader.atEnd() && !reader.hasError()) { while (!reader.atEnd() && !reader.hasError()) {
reader.readNextStartElement(); reader.readNextStartElement();
if (reader.name() == QLatin1String("message")) { if (reader.name() == QLatin1String("message")) {
QString message = reader.readElementText(); const auto message = reader.readElementText();
if (!message.isEmpty()) { if (!message.isEmpty()) {
return message; return message;
} }