chore: move RepositoryError into dedicated file
This commit is contained in:
parent
ab9d4bfa13
commit
6611643424
2 changed files with 25 additions and 24 deletions
23
src/domain/errors.rs
Normal file
23
src/domain/errors.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
use std::fmt::Display;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RepositoryError {
|
||||
#[error("entity not found")]
|
||||
NotFound,
|
||||
#[error("conflict: {0}")]
|
||||
Conflict(String),
|
||||
#[error("unexpected data store error: {0}")]
|
||||
Unexpected(String),
|
||||
}
|
||||
|
||||
impl RepositoryError {
|
||||
pub fn conflict<T: Display>(message: T) -> Self {
|
||||
Self::Conflict(message.to_string())
|
||||
}
|
||||
|
||||
pub fn unexpected<T: Display>(message: T) -> Self {
|
||||
Self::Unexpected(message.to_string())
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
pub mod bags;
|
||||
pub mod errors;
|
||||
pub mod ids;
|
||||
pub mod listing;
|
||||
pub mod repositories;
|
||||
|
|
@ -8,28 +9,5 @@ pub mod sessions;
|
|||
pub mod timeline;
|
||||
pub mod tokens;
|
||||
pub mod users;
|
||||
use std::fmt::Display;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
// TODO: This should probably be in a file named errors.rs
|
||||
// so that it's domain::errors::RepositoryError.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RepositoryError {
|
||||
#[error("entity not found")]
|
||||
NotFound,
|
||||
#[error("conflict: {0}")]
|
||||
Conflict(String),
|
||||
#[error("unexpected data store error: {0}")]
|
||||
Unexpected(String),
|
||||
}
|
||||
|
||||
impl RepositoryError {
|
||||
pub fn conflict<T: Display>(message: T) -> Self {
|
||||
Self::Conflict(message.to_string())
|
||||
}
|
||||
|
||||
pub fn unexpected<T: Display>(message: T) -> Self {
|
||||
Self::Unexpected(message.to_string())
|
||||
}
|
||||
}
|
||||
pub use errors::RepositoryError;
|
||||
|
|
|
|||
Loading…
Reference in a new issue