aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--lib/jobs/basejob.cpp25
2 files changed, 13 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9451b8ee..5b6410f1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -219,6 +219,7 @@ if (MATRIX_DOC_PATH AND GTAD_PATH)
${API_DEFS}
VERBATIM
)
+ add_custom_target(update-api DEPENDS generate-unformatted-api)
if (ABS_CLANG_FORMAT)
set(CLANG_FORMAT_ARGS -i -sort-includes ${CLANG_FORMAT_ARGS})
# FIXME: the list of files should be produced after GTAD has run.
@@ -237,9 +238,7 @@ if (MATRIX_DOC_PATH AND GTAD_PATH)
${ABS_CLANG_FORMAT} ${CLANG_FORMAT_ARGS} ${api_ALL_SRCS}
DEPENDS generate-unformatted-api
VERBATIM)
- add_custom_target(update-api DEPENDS format-api)
- else()
- add_custom_target(update-api DEPENDS generate-unformatted-api)
+ add_dependencies(update-api format-api)
endif()
endif()
endif()
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)