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:
parent
a0aef50674
commit
6253adf768
@ -1,6 +1,6 @@
|
|||||||
use activitypub::{actor::Group, collection::OrderedCollection, object::Image, CustomObject};
|
use activitypub::{actor::Group, collection::OrderedCollection, object::Image, CustomObject};
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, ExpressionMethods, QueryDsl, QueryResult, RunQueryDsl, SaveChangesDsl};
|
use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl};
|
||||||
use openssl::{
|
use openssl::{
|
||||||
hash::MessageDigest,
|
hash::MessageDigest,
|
||||||
pkey::{PKey, Private},
|
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
|
blogs::table
|
||||||
.filter(blogs::custom_domain.eq(host))
|
.filter(blogs::custom_domain.eq(host))
|
||||||
.first::<Blog>(&*c.conn)
|
.first::<Blog>(&*c.conn)
|
||||||
|
.map_err(|_| Error::NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result<Blog> {
|
||||||
|
@ -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 {
|
impl<'r> Responder<'r> for ErrorPage {
|
||||||
fn respond_to(self, req: &Request) -> response::Result<'r> {
|
fn respond_to(self, req: &Request) -> response::Result<'r> {
|
||||||
let rockets = req.guard::<PlumeRocket>().unwrap();
|
let rockets = req.guard::<PlumeRocket>().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user