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-05-28 17:54:01 +02:00 committed by Igor Galić
parent a0aef50674
commit 6253adf768
No known key found for this signature in database
GPG Key ID: ACFEFF7F6A123A86
2 changed files with 3 additions and 8 deletions

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> {

View File

@ -14,12 +14,6 @@ impl From<Error> for ErrorPage {
}
}
impl From<diesel::result::Error> for ErrorPage {
fn from(err: diesel::result::Error) -> ErrorPage {
ErrorPage(plume_models::Error::Db(err))
}
}
impl<'r> Responder<'r> for ErrorPage {
fn respond_to(self, req: &Request) -> response::Result<'r> {
let rockets = req.guard::<PlumeRocket>().unwrap();