greentic_session/
error.rs

1pub use greentic_types::{ErrorCode, GreenticError};
2use greentic_types::{GResult, SessionKey};
3pub type SessionResult<T> = GResult<T>;
4
5pub(crate) fn serde_error(err: serde_json::Error) -> GreenticError {
6    GreenticError::new(ErrorCode::Internal, err.to_string())
7}
8
9#[cfg(feature = "redis")]
10pub(crate) fn redis_error(err: redis::RedisError) -> GreenticError {
11    GreenticError::new(ErrorCode::Unavailable, err.to_string())
12}
13
14pub(crate) fn invalid_argument(msg: impl Into<String>) -> GreenticError {
15    GreenticError::new(ErrorCode::InvalidInput, msg.into())
16}
17
18pub(crate) fn not_found(key: &SessionKey) -> GreenticError {
19    GreenticError::new(
20        ErrorCode::NotFound,
21        format!("session {} was not found", key.as_str()),
22    )
23}