Skip to main content

quokka_session/
error.rs

1use axum::http::StatusCode;
2
3#[derive(Clone, Debug, thiserror::Error)]
4pub enum Error {
5    #[error("Unable to get extension from session")]
6    SessionExtensionMissing(String),
7    #[error("Cannot convert extension {0} to type {1}")]
8    SessionExtensionWrongFormat(String, String),
9    #[error("{0}")]
10    InternalServerError(String, StatusCode),
11}
12
13pub type Result<T> = std::result::Result<T, Error>;
14
15impl From<sqlx::Error> for Error {
16    fn from(value: sqlx::Error) -> Self {
17        match value {
18            sqlx::Error::RowNotFound | sqlx::Error::ColumnNotFound(_) => Self::InternalServerError(
19                "Unable to find session".to_string(),
20                StatusCode::NOT_FOUND,
21            ),
22
23            error => {
24                tracing::error!(
25                    ?error,
26                    "Error while trying to request session info from database"
27                );
28
29                Self::InternalServerError(
30                    "Internal Server Error".to_string(),
31                    StatusCode::INTERNAL_SERVER_ERROR,
32                )
33            }
34        }
35    }
36}