diff options
Diffstat (limited to 'src/index')
| -rw-r--r-- | src/index/app.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/index/app.rs b/src/index/app.rs index a4ef57f..a3456c0 100644 --- a/src/index/app.rs +++ b/src/index/app.rs @@ -1,8 +1,8 @@ use sqlx::sqlite::SqlitePool; -use crate::{ - error::BoxedError, - repo::channel::{self, Channel, Provider as _}, +use crate::repo::{ + channel::{self, Channel, Provider as _}, + error::NotFound as _, }; pub struct Index<'a> { @@ -14,11 +14,23 @@ impl<'a> Index<'a> { Self { db } } - pub async fn channel(&self, channel: &channel::Id) -> Result<Channel, BoxedError> { + pub async fn channel(&self, channel: &channel::Id) -> Result<Channel, Error> { let mut tx = self.db.begin().await?; - let channel = tx.channels().by_id(channel).await?; + let channel = tx + .channels() + .by_id(channel) + .await + .not_found(|| Error::ChannelNotFound(channel.clone()))?; tx.commit().await?; Ok(channel) } } + +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("channel {0} not found")] + ChannelNotFound(channel::Id), + #[error("database error: {0}")] + DatabaseError(#[from] sqlx::Error), +} |
