about summary refs log tree commit diff
path: root/finito-postgres/src/error.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2018-12-13T15·53+0100
committerVincent Ambo <mail@tazj.in>2018-12-13T15·53+0100
commitb7481172252d6f00546e94534b05d011b4105843 (patch)
tree3d3d3024d7d45d3875ad651f01b4df91acd7967e /finito-postgres/src/error.rs
parent42d56713bd6bbaf213cac37ff85fb1c64188fec5 (diff)
feat(postgres): Introduce database connection pool
Adds an r2d2 database connection pool to the backend type. This makes
it possible for separate FSMs to run at the same time through the same
backend, by retrieving separate connections.
Diffstat (limited to 'finito-postgres/src/error.rs')
-rw-r--r--finito-postgres/src/error.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/finito-postgres/src/error.rs b/finito-postgres/src/error.rs
index 0bf7f4018591..e130d18361f1 100644
--- a/finito-postgres/src/error.rs
+++ b/finito-postgres/src/error.rs
@@ -7,8 +7,9 @@ use uuid::Uuid;
 use std::error::Error as StdError;
 
 // errors to chain:
-use serde_json::Error as JsonError;
 use postgres::Error as PgError;
+use r2d2_postgres::r2d2::Error as PoolError;
+use serde_json::Error as JsonError;
 
 pub type Result<T> = result::Result<T, Error>;
 
@@ -26,6 +27,9 @@ pub enum ErrorKind {
     /// Errors occuring during communication with the database.
     Database(String),
 
+    /// Errors with the database connection pool.
+    DBPool(String),
+
     /// State machine could not be found.
     FSMNotFound(Uuid),
 
@@ -43,6 +47,9 @@ impl fmt::Display for Error {
             Database(err) =>
                 format!("PostgreSQL error: {}", err),
 
+            DBPool(err) =>
+                format!("Database connection pool error: {}", err),
+
             FSMNotFound(id) =>
                 format!("FSM with ID {} not found", id),
 
@@ -80,6 +87,12 @@ impl From<PgError> for ErrorKind {
     }
 }
 
+impl From<PoolError> for ErrorKind {
+    fn from(err: PoolError) -> ErrorKind {
+        ErrorKind::DBPool(err.to_string())
+    }
+}
+
 /// Helper trait that makes it possible to supply contextual
 /// information with an error.
 pub trait ResultExt<T> {