feat: set up basic sessions

This commit is contained in:
Andrew Rioux
2025-01-28 03:10:43 -05:00
parent bee66a8d6c
commit bf879bb081
23 changed files with 862 additions and 106 deletions
+40
View File
@@ -1,13 +1,21 @@
#[derive(Debug)]
pub enum Error {
Generic(String),
UserCreate(String),
#[cfg(feature = "ssr")]
Sqlx(sqlx::Error),
#[cfg(feature = "ssr")]
TokioJoin(tokio::task::JoinError),
#[cfg(feature = "ssr")]
Pbkdf2(pbkdf2::password_hash::errors::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Generic(err) => {
write!(f, "generic error: {err}")
}
Error::UserCreate(err) => {
write!(f, "user create error: {err}")
}
@@ -15,6 +23,14 @@ impl std::fmt::Display for Error {
Error::Sqlx(err) => {
write!(f, "sqlx error: {err:?}")
}
#[cfg(feature = "ssr")]
Error::TokioJoin(err) => {
write!(f, "tokio join error: {err:?}")
}
#[cfg(feature = "ssr")]
Error::Pbkdf2(err) => {
write!(f, "password hash error: {err:?}")
}
}
}
}
@@ -24,14 +40,38 @@ impl std::error::Error for Error {
match self {
#[cfg(feature = "ssr")]
Error::Sqlx(err) => Some(err),
#[cfg(feature = "ssr")]
Error::TokioJoin(err) => Some(err),
_ => None,
}
}
}
impl std::str::FromStr for Error {
type Err = Self;
fn from_str(err: &str) -> Result<Self, Self::Err> {
Ok(Self::Generic(err.to_string()))
}
}
#[cfg(feature = "ssr")]
impl From<sqlx::Error> for Error {
fn from(err: sqlx::Error) -> Self {
Self::Sqlx(err)
}
}
#[cfg(feature = "ssr")]
impl From<tokio::task::JoinError> for Error {
fn from(err: tokio::task::JoinError) -> Self {
Self::TokioJoin(err)
}
}
#[cfg(feature = "ssr")]
impl From<pbkdf2::password_hash::errors::Error> for Error {
fn from(err: pbkdf2::password_hash::errors::Error) -> Self {
Self::Pbkdf2(err)
}
}