about summary refs log tree commit diff
path: root/src/db.rs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-04-08T17·22+0200
committerVincent Ambo <tazjin@gmail.com>2018-04-08T17·22+0200
commit15d460bab3d45a8253c8d1ae9cdd69223fa78095 (patch)
treedf75e08aca78908ca51f0ca11507cd020375d122 /src/db.rs
parentfdc1abe7cc6e2552c30df6c124aca711b130d496 (diff)
refactor(db): Use ConverseError instead of unwrapping/expecting
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/db.rs b/src/db.rs
index 1aa6ff73c78c..ed4a78659332 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1,10 +1,10 @@
 //! This module implements the database connection actor.
 
 use actix::prelude::*;
-use actix_web::Error;
 use diesel::prelude::*;
 use diesel::r2d2::{Pool, ConnectionManager};
 use models::*;
+use errors::Result;
 
 /// The DB actor itself. Several of these will be run in parallel by
 /// `SyncArbiter`.
@@ -19,7 +19,7 @@ impl Actor for DbExecutor {
 pub struct ListThreads;
 
 impl Message for ListThreads {
-    type Result = Result<Vec<Thread>, Error>;
+    type Result = Result<Vec<Thread>>;
 }
 
 impl Handler<ListThreads> for DbExecutor {
@@ -28,8 +28,8 @@ impl Handler<ListThreads> for DbExecutor {
     fn handle(&mut self, _: ListThreads, _: &mut Self::Context) -> Self::Result {
         use schema::threads::dsl::*;
 
-        let conn = self.0.get().unwrap();
-        let results = threads.load::<Thread>(&conn).expect("Error loading threads");
+        let conn = self.0.get()?;
+        let results = threads.load::<Thread>(&conn)?;
         Ok(results)
     }
 }
@@ -39,7 +39,7 @@ impl Handler<ListThreads> for DbExecutor {
 pub struct GetThread(pub i32);
 
 impl Message for GetThread {
-    type Result = Result<(Thread, Vec<Post>), Error>;
+    type Result = Result<(Thread, Vec<Post>)>;
 }
 
 impl Handler<GetThread> for DbExecutor {
@@ -48,13 +48,11 @@ impl Handler<GetThread> for DbExecutor {
     fn handle(&mut self, msg: GetThread, _: &mut Self::Context) -> Self::Result {
         use schema::threads::dsl::*;
 
-        let conn = self.0.get().unwrap();
+        let conn = self.0.get()?;
         let thread_result: Thread = threads
-            .find(msg.0).first(&conn)
-            .expect("Error loading thread");
+            .find(msg.0).first(&conn)?;
 
-        let post_list = Post::belonging_to(&thread_result)
-            .load::<Post>(&conn).expect("Error loading posts for thread");
+        let post_list = Post::belonging_to(&thread_result).load::<Post>(&conn)?;
 
         Ok((thread_result, post_list))
     }