1
0
Fork 0

improve error messages (#6003)

This commit is contained in:
Wilfried Goesgens 2018-07-26 16:02:25 +02:00 committed by Jan
parent 62ca1235ac
commit 69955cb2cb
1 changed files with 29 additions and 13 deletions

View File

@ -52,16 +52,31 @@ constexpr auto FeatureName = "Restore";
/// @brief check whether HTTP response is valid, complete, and not an error
arangodb::Result checkHttpResponse(
arangodb::httpclient::SimpleHttpClient& client,
std::unique_ptr<arangodb::httpclient::SimpleHttpResult>& response) {
std::unique_ptr<arangodb::httpclient::SimpleHttpResult>& response,
char const* requestAction,
std::string const& originalRequest) {
using arangodb::basics::StringUtils::itoa;
if (response == nullptr || !response->isComplete()) {
return {TRI_ERROR_INTERNAL,
"got invalid response from server: " + client.getErrorMessage()};
"got invalid response from server: '" +
client.getErrorMessage() +
"' while executing '" +
requestAction +
"' with this payload: '" +
originalRequest +
"'"
};
}
if (response->wasHttpError()) {
return {TRI_ERROR_INTERNAL, "got invalid response from server: HTTP " +
itoa(response->getHttpReturnCode()) + ": " +
response->getHttpReturnMessage()};
return {TRI_ERROR_INTERNAL,
"got invalid response from server: HTTP " +
itoa(response->getHttpReturnCode()) + ": '" +
response->getHttpReturnMessage() +
"' while executing '" +
requestAction +
"' with this payload: '" +
originalRequest +
"'"};
}
return {TRI_ERROR_NO_ERROR};
}
@ -161,12 +176,12 @@ arangodb::Result tryCreateDatabase(std::string const& name) {
if (returnCode == static_cast<int>(ResponseCode::UNAUTHORIZED) ||
returnCode == static_cast<int>(ResponseCode::FORBIDDEN)) {
// invalid authorization
auto res = ::checkHttpResponse(*httpClient, response);
auto res = ::checkHttpResponse(*httpClient, response, "creating database", body);
return {TRI_ERROR_FORBIDDEN, res.errorMessage()};
}
// any other error
auto res = ::checkHttpResponse(*httpClient, response);
auto res = ::checkHttpResponse(*httpClient, response, "creating database", body);
return {TRI_ERROR_INTERNAL, res.errorMessage()};
}
@ -276,7 +291,7 @@ arangodb::Result sendRestoreCollection(
httpClient.getErrorMessage()};
}
if (response->wasHttpError()) {
return ::checkHttpResponse(httpClient, response);
return ::checkHttpResponse(httpClient, response, "restoring collection", body);
}
return {TRI_ERROR_NO_ERROR};
@ -299,7 +314,7 @@ arangodb::Result sendRestoreIndexes(
httpClient.getErrorMessage()};
}
if (response->wasHttpError()) {
return ::checkHttpResponse(httpClient, response);
return ::checkHttpResponse(httpClient, response, "restoring indices", body);
}
return {TRI_ERROR_NO_ERROR};
@ -324,7 +339,7 @@ arangodb::Result sendRestoreData(
httpClient.getErrorMessage()};
}
if (response->wasHttpError()) {
return ::checkHttpResponse(httpClient, response);
return ::checkHttpResponse(httpClient, response, "restoring payload", "");
}
return {TRI_ERROR_NO_ERROR};
@ -505,11 +520,12 @@ arangodb::Result restoreView(arangodb::httpclient::SimpleHttpClient& httpClient,
std::unique_ptr<SimpleHttpResult> response(httpClient.request(arangodb::rest::RequestType::PUT,
url, body.c_str(), body.size()));
if (response == nullptr || !response->isComplete()) {
return {TRI_ERROR_INTERNAL, "got invalid response from server: " +
httpClient.getErrorMessage()};
return {TRI_ERROR_INTERNAL, "got invalid response from server: '" +
httpClient.getErrorMessage() + "' while trying to restore view: '" +
body.c_str() + "'"};
}
if (response->wasHttpError()) {
return ::checkHttpResponse(httpClient, response);
return ::checkHttpResponse(httpClient, response, "restoring view", body);
}
return {TRI_ERROR_NO_ERROR};