mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 09:10:49 +00:00
osu: make save
command use interaction
This commit is contained in:
parent
e777d4d634
commit
068dd48550
6 changed files with 94 additions and 59 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue