warp_sessions/
error.rs

1use std::error::Error;
2use std::fmt::Display;
3use warp::reject::Reject;
4
5/// Error type that converts to a warp::Rejection
6#[derive(Debug)]
7pub enum SessionError {
8    /// Represents an error which occurred while loading a session from
9    /// the backing session store.
10    LoadError { source: async_session::Error },
11
12    /// Represents an error that occurred while saving a session to
13    /// the backing session store.
14    StoreError { source: async_session::Error },
15
16    /// Represents an error that occurred while destroying a session
17    /// record from the backing session store.
18    DestroyError { source: async_session::Error },
19}
20
21impl Error for SessionError {
22    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23        match *self {
24            SessionError::LoadError { ref source } => Some(source.as_ref()),
25            SessionError::StoreError { ref source } => Some(source.as_ref()),
26            SessionError::DestroyError { ref source } => Some(source.as_ref()),
27        }
28    }
29}
30
31impl Display for SessionError {
32    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
33        match *self {
34            SessionError::LoadError { .. } => {
35                write!(f, "Failed to load session")
36            }
37            SessionError::StoreError { .. } => {
38                write!(f, "Failed to store session")
39            }
40            SessionError::DestroyError { .. } => {
41                write!(f, "Failed to destroy session")
42            }
43        }
44    }
45}
46
47impl Reject for SessionError {}