diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-11 19:24:39 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-11 19:24:39 +0200 |
commit | 0db2db1d247a0a4e6e6545ec0d72879416e6226b (patch) | |
tree | 2c99f93c1deb01168a7ed9aa1c908d93e24709b6 /lib/jobs | |
parent | ff3c8481f499e42d51e1a8ef5f75a4e634858862 (diff) | |
download | libquotient-0db2db1d247a0a4e6e6545ec0d72879416e6226b.tar.gz libquotient-0db2db1d247a0a4e6e6545ec0d72879416e6226b.zip |
BaseJob::prepareError(): be more tolerant to empty error payloads
TooManyRequests can come without a payload, apparently.
Diffstat (limited to 'lib/jobs')
-rw-r--r-- | lib/jobs/basejob.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 3978dbcb..d7daa170 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -508,17 +508,13 @@ BaseJob::Status BaseJob::prepareResult() { return Success; } BaseJob::Status BaseJob::prepareError() { - // Since it's an error, the expected content type is of no help; - // check the actually advertised content type instead - if (reply()->rawHeader("Content-Type") != "application/json") - return NoError; // Retain the status if the error payload is not JSON - - if (const auto status = d->parseJson(); !status.good()) - return status; - - if (d->jsonResponse.isArray()) - return { IncorrectResponse, - tr("Malformed error JSON: an array instead of an object") }; + if (!d->rawResponse.isEmpty()) { + if (const auto status = d->parseJson(); !status.good()) + return status; // If there's anything there, it should be JSON + if (d->jsonResponse.isArray()) // ...specifically, a JSON object + return { IncorrectResponse, + tr("Malformed error JSON: an array instead of an object") }; + } const auto& errorJson = jsonData(); const auto errCode = errorJson.value("errcode"_ls).toString(); @@ -534,6 +530,7 @@ BaseJob::Status BaseJob::prepareError() return { TooManyRequestsError, msg }; } + if (errCode == "M_CONSENT_NOT_GIVEN") { d->errorUrl = errorJson.value("consent_uri"_ls).toString(); return { UserConsentRequiredError }; @@ -552,10 +549,10 @@ BaseJob::Status BaseJob::prepareError() return { UserDeactivated }; // Not localisable on the client side - if (errorJson.contains("error"_ls)) - d->status.message = errorJson.value("error"_ls).toString(); + if (errorJson.contains("error"_ls)) // Keep the code, update the message + return { d->status.code, errorJson.value("error"_ls).toString() }; - return d->status; + return NoError; // Retain the status if the error payload is not recognised } QJsonValue BaseJob::takeValueFromJson(const QString& key) |