simplify / unify error handling

We want to return a Result<Blog>, instead of a QueryResult<Blog>.
We can use map_err() to map it to the desired error type.

thanks to review from @BaptisteGelez & @fdb-hiroshima.
This commit is contained in:
Igor Galić
2019-08-14 23:51:13 +02:00
committed by Igor Galić
parent a0aef50674
commit 6253adf768
2 changed files with 3 additions and 8 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
use activitypub::{actor::Group, collection::OrderedCollection, object::Image, CustomObject};
use chrono::NaiveDateTime;
use diesel::{self, ExpressionMethods, QueryDsl, QueryResult, RunQueryDsl, SaveChangesDsl};
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
use openssl::{
hash::MessageDigest,
pkey::{PKey, Private},
@@ -195,10 +195,11 @@ impl Blog {
}
}
pub fn find_by_host(c: &PlumeRocket, host: Host) -> QueryResult<Blog> {
pub fn find_by_host(c: &PlumeRocket, host: Host) -> Result<Blog> {
blogs::table
.filter(blogs::custom_domain.eq(host))
.first::<Blog>(&*c.conn)
.map_err(|_| Error::NotFound)
}
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {