From 285c1adb1df9379e2ccf9a9e0956529fb6e72fc1 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 17 Oct 2018 19:13:07 +0200 Subject: [PATCH] attempt to fix release-3.4#98: Unsuccessful arangorestore needs better error message (#6949) --- arangosh/Dump/DumpFeature.cpp | 16 ++++++++++++---- arangosh/Restore/RestoreFeature.cpp | 13 +++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/arangosh/Dump/DumpFeature.cpp b/arangosh/Dump/DumpFeature.cpp index 84df17cb69..2d62d83b2a 100644 --- a/arangosh/Dump/DumpFeature.cpp +++ b/arangosh/Dump/DumpFeature.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -82,9 +83,16 @@ arangodb::Result checkHttpResponse( "got invalid response from server: " + client.getErrorMessage()}; } if (response->wasHttpError()) { - return {TRI_ERROR_INTERNAL, "got invalid response from server: HTTP " + - itoa(response->getHttpReturnCode()) + ": " + - response->getHttpReturnMessage()}; + int errorNum = TRI_ERROR_INTERNAL; + std::string errorMsg = response->getHttpReturnMessage(); + std::shared_ptr bodyBuilder(response->getBodyVelocyPack()); + arangodb::velocypack::Slice error = bodyBuilder->slice(); + if (!error.isNone() && error.hasKey(arangodb::StaticStrings::ErrorMessage)) { + errorNum = error.get(arangodb::StaticStrings::ErrorNum).getNumericValue(); + errorMsg = error.get(arangodb::StaticStrings::ErrorMessage).copyString(); + } + return {errorNum, "got invalid response from server: HTTP " + + itoa(response->getHttpReturnCode()) + ": " + errorMsg}; } return {TRI_ERROR_NO_ERROR}; } @@ -284,7 +292,7 @@ arangodb::Result dumpCollection(arangodb::httpclient::SimpleHttpClient& client, } if (!headerExtracted) { // NOT else, fallthrough from outer or inner above return {TRI_ERROR_REPLICATION_INVALID_RESPONSE, - "got invalid response server: required header is missing"}; + "got invalid response from server: required header is missing"}; } // now actually write retrieved data to dump file diff --git a/arangosh/Restore/RestoreFeature.cpp b/arangosh/Restore/RestoreFeature.cpp index d02b71a557..c61cbb04c8 100644 --- a/arangosh/Restore/RestoreFeature.cpp +++ b/arangosh/Restore/RestoreFeature.cpp @@ -33,6 +33,7 @@ #include "ApplicationFeatures/ApplicationServer.h" #include "Basics/FileUtils.h" #include "Basics/Result.h" +#include "Basics/StaticStrings.h" #include "Basics/StringUtils.h" #include "Basics/VelocyPackHelper.h" #include "Logger/Logger.h" @@ -71,10 +72,18 @@ arangodb::Result checkHttpResponse( }; } if (response->wasHttpError()) { - return {TRI_ERROR_INTERNAL, + int errorNum = TRI_ERROR_INTERNAL; + std::string errorMsg = response->getHttpReturnMessage(); + std::shared_ptr bodyBuilder(response->getBodyVelocyPack()); + arangodb::velocypack::Slice error = bodyBuilder->slice(); + if (!error.isNone() && error.hasKey(arangodb::StaticStrings::ErrorMessage)) { + errorNum = error.get(arangodb::StaticStrings::ErrorNum).getNumericValue(); + errorMsg = error.get(arangodb::StaticStrings::ErrorMessage).copyString(); + } + return {errorNum, "got invalid response from server: HTTP " + itoa(response->getHttpReturnCode()) + ": '" + - response->getHttpReturnMessage() + + errorMsg + "' while executing '" + requestAction + "' with this payload: '" +