36 lines
971 B
Rust
36 lines
971 B
Rust
use thiserror::Error;
|
|
|
|
/// Errors that can occur during transaction or session operations.
|
|
#[derive(Debug, Error)]
|
|
pub enum TransactionError {
|
|
#[error("not found: {0}")]
|
|
NotFound(String),
|
|
|
|
#[error("transaction already active for session: {0}")]
|
|
AlreadyActive(String),
|
|
|
|
#[error("write conflict detected (code 112): {0}")]
|
|
WriteConflict(String),
|
|
|
|
#[error("session expired: {0}")]
|
|
SessionExpired(String),
|
|
|
|
#[error("invalid transaction state: {0}")]
|
|
InvalidState(String),
|
|
}
|
|
|
|
impl TransactionError {
|
|
/// Returns the error code.
|
|
pub fn code(&self) -> i32 {
|
|
match self {
|
|
TransactionError::NotFound(_) => 251,
|
|
TransactionError::AlreadyActive(_) => 256,
|
|
TransactionError::WriteConflict(_) => 112,
|
|
TransactionError::SessionExpired(_) => 6100,
|
|
TransactionError::InvalidState(_) => 263,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub type TransactionResult<T> = Result<T, TransactionError>;
|