summaryrefslogtreecommitdiff
path: root/src/index
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-09-18 01:27:47 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-09-18 12:17:46 -0400
commitcce6662d635bb2115f9f2a7bab92cc105166e761 (patch)
tree9d1edfea364a3b72cf40c78d67ce05e3e68c84df /src/index
parent921f38a73e5d58a5a6077477a8b52d2705798f55 (diff)
App methods now return errors that allow not-found cases to be distinguished.
Diffstat (limited to 'src/index')
-rw-r--r--src/index/app.rs22
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),
+}