summaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/misc/last_error.cpp
diff options
context:
space:
mode:
authorkomels <[email protected]>2022-04-15 16:53:39 +0300
committerkomels <[email protected]>2022-04-15 16:53:39 +0300
commit703a2fb6e100d202d1c7fcd052d73bd5affef408 (patch)
tree22b7320c06bb04d86dbf7b9af9ae44281331cd15 /library/cpp/tvmauth/client/misc/last_error.cpp
parent3375bbfda1e2afb03aa2072bf5f2f2c3a26026e8 (diff)
Move 'kikimr/yndx'-depending tests out of ydb/core
ref:0a380e13308d579e0545a76924330d1ca5129c43
Diffstat (limited to 'library/cpp/tvmauth/client/misc/last_error.cpp')
-rw-r--r--library/cpp/tvmauth/client/misc/last_error.cpp115
1 files changed, 0 insertions, 115 deletions
diff --git a/library/cpp/tvmauth/client/misc/last_error.cpp b/library/cpp/tvmauth/client/misc/last_error.cpp
deleted file mode 100644
index a6279bb1efe..00000000000
--- a/library/cpp/tvmauth/client/misc/last_error.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-#include "last_error.h"
-
-#include <util/string/builder.h>
-
-namespace NTvmAuth {
- TLastError::TLastError()
- : LastErrors_(MakeIntrusiveConst<TLastErrors>())
- {
- }
-
- TString TLastError::GetLastError(bool isOk, EType* type) const {
- if (isOk) {
- return OK_;
- }
-
- const TLastErrorsPtr ptr = LastErrors_.Get();
-
- for (const TLastErr& err : ptr->Errors) {
- if (err && err->first == EType::NonRetriable) {
- if (type) {
- *type = EType::NonRetriable;
- }
- return err->second;
- }
- }
-
- for (const TLastErr& err : ptr->Errors) {
- if (err) {
- if (type) {
- *type = EType::Retriable;
- }
- return err->second;
- }
- }
-
- if (type) {
- *type = EType::NonRetriable;
- }
- return "Internal client error: failed to collect last useful error message, please report this message to [email protected]";
- }
-
- TString TLastError::ProcessHttpError(TLastError::EScope scope,
- TStringBuf path,
- int code,
- const TString& msg) const {
- TString err = TStringBuilder() << "Path:" << path << ".Code=" << code << ": " << msg;
-
- ProcessError(code >= 400 && code < 500 ? EType::NonRetriable
- : EType::Retriable,
- scope,
- err);
-
- return err;
- }
-
- void TLastError::ProcessError(TLastError::EType type, TLastError::EScope scope, const TStringBuf msg) const {
- Update(scope, [&](TLastErr& lastError) {
- if (lastError && lastError->first == EType::NonRetriable && type == EType::Retriable) {
- return false;
- }
-
- TString err = TStringBuilder() << scope << ": " << msg;
- err.erase(std::remove(err.begin(), err.vend(), '\r'), err.vend());
- std::replace(err.begin(), err.vend(), '\n', ' ');
-
- lastError = {type, std::move(err)};
- return true;
- });
- }
-
- void TLastError::ClearError(TLastError::EScope scope) {
- Update(scope, [&](TLastErr& lastError) {
- if (!lastError) {
- return false;
- }
-
- lastError.Clear();
- return true;
- });
- }
-
- void TLastError::ClearErrors() {
- for (size_t idx = 0; idx < (size_t)EScope::COUNT; ++idx) {
- ClearError((EScope)idx);
- }
- }
-
- void TLastError::ThrowLastError() {
- EType type;
- TString err = GetLastError(false, &type);
-
- switch (type) {
- case EType::NonRetriable:
- ythrow TNonRetriableException()
- << "Failed to start TvmClient. Do not retry: "
- << err;
- case EType::Retriable:
- ythrow TRetriableException()
- << "Failed to start TvmClient. You can retry: "
- << err;
- }
- }
-
- template <typename Func>
- void TLastError::Update(TLastError::EScope scope, Func func) const {
- Y_VERIFY(scope != EScope::COUNT);
-
- TLastErrors errs = *LastErrors_.Get();
- TLastErr& lastError = errs.Errors[(size_t)scope];
-
- if (func(lastError)) {
- LastErrors_.Set(MakeIntrusiveConst<TLastErrors>(std::move(errs)));
- }
- }
-}