about summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabui@proton.me>2026-10-14 08:36:18 +0300
committerAlexander_Kabui <alexanderkabui@proton.me>2026-10-14 08:36:18 +0300
commitdfa576b0f821dc8a0beba7acebeed81dc831b17a (patch)
tree5e086108c3afe303ed1707289f0c25635670e8e9 /src/error.rs
parent630fec9b00e85436638b93ebf8902579ae436247 (diff)
parent22ff53e2d65e47df27d76aa7420a146074c00282 (diff)
downloadgenenetwork4-dfa576b0f821dc8a0beba7acebeed81dc831b17a.tar.gz
Merge remote-tracking branch 'origin/gn4-devdb-switch' into gn4-integration
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index 3f9479a..7daa103 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -111,6 +111,32 @@ impl ApiError {
         self.next = Some(next.to_string());
         self
     }
+
+    /// Map a database failure onto the shared error contract. An
+    /// unreachable/unconfigured database (minted at `db::pool()`) is a
+    /// typed 503 `db_unavailable` -- the database itself is down, not
+    /// this request; a query failure on an established pool keeps the
+    /// existing 500 `database_error`. Every DB-touching route maps
+    /// through this one place, so all four `From`-adapter shapes and
+    /// the inline `map_err` sites agree.
+    pub fn from_db(error: crate::db::DbError, operation_id: &str) -> ApiError {
+        match error {
+            crate::db::DbError::Unavailable(detail) => ApiError::new(
+                StatusCode::SERVICE_UNAVAILABLE,
+                "db_unavailable",
+                "Database unavailable",
+                detail,
+                operation_id,
+            ),
+            crate::db::DbError::Query(error) => ApiError::new(
+                StatusCode::INTERNAL_SERVER_ERROR,
+                "database_error",
+                "Database error",
+                error.to_string(),
+                operation_id,
+            ),
+        }
+    }
 }
 
 impl IntoResponse for ApiError {