osu: make save command use interaction

This commit is contained in:
Natsu Kagami 2025-02-22 17:13:57 +01:00 committed by Natsu Kagami
parent e777d4d634
commit 068dd48550
6 changed files with 94 additions and 59 deletions

View file

@ -36,9 +36,27 @@ pub mod errors {
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("sqlx error: {:?}", .0)]
SQLx(#[from] sqlx::Error),
SQLx(sqlx::Error),
#[error("sqlx migration error: {:?}", .0)]
Migration(#[from] sqlx::migrate::MigrateError),
#[error("values already existed for: {}", .0)]
Duplicate(String),
}
impl From<sqlx::Error> for Error {
fn from(value: sqlx::Error) -> Self {
match value {
// if we can match a constraint error, give it a special case.
sqlx::Error::Database(database_error) => {
let msg = database_error.message();
match msg.strip_prefix("UNIQUE constraint failed: ") {
Some(con) => Error::Duplicate(con.to_owned()),
None => Error::SQLx(sqlx::Error::Database(database_error)),
}
}
e => Error::SQLx(e),
}
}
}
}