summaryrefslogtreecommitdiff
path: root/src/channel/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/app.rs')
-rw-r--r--src/channel/app.rs16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/channel/app.rs b/src/channel/app.rs
index 7c0b107..5d6cada 100644
--- a/src/channel/app.rs
+++ b/src/channel/app.rs
@@ -5,7 +5,7 @@ use sqlx::sqlite::SqlitePool;
use super::{repo::Provider as _, Channel, History, Id};
use crate::{
clock::DateTime,
- db::NotFound,
+ db::{Duplicate as _, NotFound as _},
event::{repo::Provider as _, Broadcaster, Event, Sequence},
message::repo::Provider as _,
};
@@ -27,7 +27,7 @@ impl<'a> Channels<'a> {
.channels()
.create(name, &created)
.await
- .map_err(|err| CreateError::from_duplicate_name(err, name))?;
+ .duplicate(|| CreateError::DuplicateName(name.into()))?;
tx.commit().await?;
self.events
@@ -133,18 +133,6 @@ pub enum Error {
DatabaseError(#[from] sqlx::Error),
}
-impl CreateError {
- fn from_duplicate_name(error: sqlx::Error, name: &str) -> Self {
- if let Some(error) = error.as_database_error() {
- if error.is_unique_violation() {
- return Self::DuplicateName(name.into());
- }
- }
-
- Self::from(error)
- }
-}
-
#[derive(Debug, thiserror::Error)]
pub enum InternalError {
#[error(transparent)]