fish_lib/game/errors/
repository.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use thiserror::Error;

#[derive(Error, Debug)]
pub enum GameRepositoryError {
    #[error("Foreign key violation: user with id '{id}' was not found")]
    ForeignKeyViolationUserNotFound { id: i64 },
}

impl GameRepositoryError {
    pub fn foreign_key_violation_user_not_found(id: i64) -> Self {
        Self::ForeignKeyViolationUserNotFound { id }
    }

    pub fn is_foreign_key_violation_user_not_found(&self) -> bool {
        matches!(self, Self::ForeignKeyViolationUserNotFound { .. })
    }
}