From f84a272f537453398439c3c3be6ec823384f7a41 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 15 Apr 2019 03:07:04 +0200 Subject: [PATCH] Added support for "errors" in addition to "error". #12 --- src/easy/entity.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/easy/entity.cpp b/src/easy/entity.cpp index fdce7d3..06534b3 100644 --- a/src/easy/entity.cpp +++ b/src/easy/entity.cpp @@ -69,7 +69,7 @@ void Easy::Entity::from_string(const string &json) ttdebug << "ERROR: JSON string holds no object\n"; ttdebug << "String was: " << json << '\n'; } - else if (!_tree["error"].isNull()) + else if (!_tree["error"].isNull() || !_tree["errors"].isNull()) { ttdebug << "ERROR: Server returned an error\n"; ttdebug << "String was: " << json << '\n'; @@ -107,7 +107,14 @@ bool Easy::Entity::check_valid(const std::vector &attributes) const const string Easy::Entity::error() const { - return get_string("error"); + string error = get_string("error"); + if (error.empty()) + { + // Pleroma uses {"errors":{"detail":"[…]"}} sometimes. + const Json::Value node = get("errors.detail"); + error = node.asString(); + } + return error; } bool Easy::Entity::was_set() const