diff --git a/common/cpp/include/asapo/common/error.h b/common/cpp/include/asapo/common/error.h index 24d78d5399cc7fa64307e44b63692596883dc2d1..d99b3aead862ff412c0ea59480405f359519df24 100644 --- a/common/cpp/include/asapo/common/error.h +++ b/common/cpp/include/asapo/common/error.h @@ -38,6 +38,7 @@ class ErrorInterface { public: virtual std::string Explain() const noexcept = 0; virtual void Append(const std::string& value) noexcept = 0; + virtual void Prepend(const std::string& value) noexcept = 0; virtual ErrorType GetErrorType() const noexcept = 0; virtual CustomErrorData* GetCustomData() = 0; virtual void SetCustomData(std::unique_ptr<CustomErrorData> data) = 0; @@ -112,6 +113,10 @@ class SimpleError: public ErrorInterface { error_ += ": " + value; } + void Prepend(const std::string& value) noexcept override { + error_ = value+": "+error_; + } + std::string Explain() const noexcept override { return error_; } diff --git a/consumer/api/cpp/src/consumer_impl.cpp b/consumer/api/cpp/src/consumer_impl.cpp index 60848dfa3353f7d6563bb0c657f4222bfd3df493..b6eb00b86c9f880014ac1e5cd1a7d70f13593829 100644 --- a/consumer/api/cpp/src/consumer_impl.cpp +++ b/consumer/api/cpp/src/consumer_impl.cpp @@ -93,19 +93,29 @@ Error ConsumerErrorFromHttpCode(const RequestOutput* response, const HttpCode &c } Error ConsumerErrorFromServerError(const Error &server_err) { if (server_err == HttpErrorTemplates::kTransferError) { - return ConsumerErrorTemplates::kInterruptedTransaction.Generate( - "error processing request: " + server_err->Explain()); + return ConsumerErrorTemplates::kInterruptedTransaction.Generate(server_err->Explain()); } else { - return ConsumerErrorTemplates::kUnavailableService.Generate( - "error processing request: " + server_err->Explain()); + return ConsumerErrorTemplates::kUnavailableService.Generate(server_err->Explain()); } } -Error ProcessRequestResponce(const Error &server_err, const RequestOutput* response, const HttpCode &code) { +Error ProcessRequestResponce(const RequestInfo &request, + const Error &server_err, + const RequestOutput* response, + const HttpCode &code) { + Error err; if (server_err != nullptr) { - return ConsumerErrorFromServerError(server_err); + err = ConsumerErrorFromServerError(server_err); + } else { + err = ConsumerErrorFromHttpCode(response, code); + } + + if (err!=nullptr) { + std::string prefix = "Error processing request" + request.api; + err->Prepend(prefix); } - return ConsumerErrorFromHttpCode(response, code); + return err; + } ConsumerImpl::ConsumerImpl(std::string server_uri, @@ -179,7 +189,7 @@ Error ConsumerImpl::ProcessRequest(RequestOutput* response, const RequestInfo &r if (err && service_uri) { service_uri->clear(); } - return ProcessRequestResponce(err, response, code); + return ProcessRequestResponce(request, err, response, code); } RequestInfo ConsumerImpl::GetDiscoveryRequest(const std::string &service_name) const { @@ -939,7 +949,7 @@ Error ConsumerImpl::GetServerVersionInfo(std::string* server_info, bool* support if (err) { return err; } - return ExtractVersionFromResponse(output.string_output,"consumer",server_info,supported); + return ExtractVersionFromResponse(output.string_output, "consumer", server_info, supported); } Error ConsumerImpl::GetVersionInfo(std::string* client_info, std::string* server_info, bool* supported) { @@ -952,7 +962,7 @@ Error ConsumerImpl::GetVersionInfo(std::string* client_info, std::string* server } if (server_info != nullptr || supported != nullptr) { - return GetServerVersionInfo(server_info,supported); + return GetServerVersionInfo(server_info, supported); } return nullptr; @@ -970,7 +980,7 @@ RequestInfo ConsumerImpl::GetDeleteStreamRequest(std::string stream, DeleteStrea } Error ConsumerImpl::DeleteStream(std::string stream, DeleteStreamOptions options) { - auto ri = GetDeleteStreamRequest(std::move(stream),options); + auto ri = GetDeleteStreamRequest(std::move(stream), options); Error err; BrokerRequestWithTimeout(ri, &err); return err; diff --git a/consumer/api/cpp/src/consumer_impl.h b/consumer/api/cpp/src/consumer_impl.h index 9fe29bdf83d7939454fe67b376fa24f9509d6531..7f7411c99e8984ea1b1c58ae7b9d747e79f3177d 100644 --- a/consumer/api/cpp/src/consumer_impl.h +++ b/consumer/api/cpp/src/consumer_impl.h @@ -46,7 +46,7 @@ struct RequestOutput { } }; -Error ProcessRequestResponce(const Error& server_err, const RequestOutput* response, const HttpCode& code); +Error ProcessRequestResponce(const RequestInfo& request, const Error& server_err, const RequestOutput* response, const HttpCode& code); Error ConsumerErrorFromNoDataResponse(const std::string& response); Error ConsumerErrorFromPartialDataResponse(const std::string& response); DataSet DecodeDatasetFromResponse(std::string response, Error* err);