From d5b8e5b019de8677015005999adef14e1e2f566d Mon Sep 17 00:00:00 2001
From: Egor Ivkov <e.o.ivkov@gmail.com>
Date: Thu, 13 Jul 2023 13:42:33 +0300
Subject: [PATCH] feat: detect cas errors from generic strings

---
 src/traft/error.rs | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/traft/error.rs b/src/traft/error.rs
index 2f3fa3bf4a..0ccfc5fb4f 100644
--- a/src/traft/error.rs
+++ b/src/traft/error.rs
@@ -83,6 +83,22 @@ impl Error {
     {
         Self::Other(error.into())
     }
+
+    /// Temporary solution until proc_cas returns structured errors
+    pub fn is_cas_err(&self) -> bool {
+        self.to_string().contains("compare-and-swap request failed")
+    }
+
+    /// Temporary solution until proc_cas returns structured errors
+    pub fn is_term_mismatch_err(&self) -> bool {
+        self.to_string()
+            .contains("operation request from different term")
+    }
+
+    /// Temporary solution until proc_cas returns structured errors
+    pub fn is_not_leader_err(&self) -> bool {
+        self.to_string().contains("not a leader")
+    }
 }
 
 impl<E> From<timeout::Error<E>> for Error
-- 
GitLab