Skip to main content

greentic_session/
error.rs

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