diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index f8fcffb3..5e36331c 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -1,6 +1,6 @@ use activitypub::{actor::Group, collection::OrderedCollection, object::Image, CustomObject}; use chrono::NaiveDateTime; -use diesel::{self, ExpressionMethods, QueryDsl, RunQueryDsl, SaveChangesDsl}; +use diesel::{self, ExpressionMethods, QueryDsl, QueryResult, RunQueryDsl, SaveChangesDsl}; use openssl::{ hash::MessageDigest, pkey::{PKey, Private}, @@ -195,14 +195,10 @@ impl Blog { } } - pub fn find_by_host(c: &PlumeRocket, host: Host) -> Result { - let from_db = blogs::table + pub fn find_by_host(c: &PlumeRocket, host: Host) -> QueryResult { + blogs::table .filter(blogs::custom_domain.eq(host)) - .limit(1) - .load::(&*c.conn)? - .into_iter() - .next(); - from_db.ok_or(Error::NotFound) + .first::(&*c.conn) } fn fetch_from_webfinger(c: &PlumeRocket, acct: &str) -> Result { diff --git a/src/routes/errors.rs b/src/routes/errors.rs index 1320a068..23f38030 100644 --- a/src/routes/errors.rs +++ b/src/routes/errors.rs @@ -14,6 +14,12 @@ impl From for ErrorPage { } } +impl From 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::().unwrap();