Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thiserror #167

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions copperd/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions copperd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ serde = { version = "1.0.201", features = ["serde_derive", "rc"] }
serde_json = "1.0.68"
serde_with = "3.8.1"
utoipa = { version = "5.0.0-alpha.0", features = ["axum_extras"] }
thiserror = "2.0.1"

# Because we can't clone tokio's `broadcast::Receiver`
async-broadcast = "0.7.1"
Expand Down
1 change: 1 addition & 0 deletions copperd/bin/edged/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ async-trait = { workspace = true }
rand = { workspace = true }
time = { workspace = true }
itertools = { workspace = true }
thiserror = { workspace = true }
32 changes: 5 additions & 27 deletions copperd/bin/edged/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{error::Error, fmt::Display, marker::PhantomData};

use axum::{
http::{header::SET_COOKIE, StatusCode},
response::{AppendHeaders, IntoResponse, Response},
Expand All @@ -13,6 +11,8 @@ use copper_edged::UserInfo;
use copper_itemdb::{client::base::client::ItemdbClient, UserId};
use rand::{distributions::Alphanumeric, Rng};
use smartstring::{LazyCompact, SmartString};
use std::marker::PhantomData;
use thiserror::Error;
use time::{Duration, OffsetDateTime};
use tokio::sync::Mutex;
use tracing::error;
Expand All @@ -30,32 +30,10 @@ const AUTH_TOKEN_LIFE_HOURS: i64 = 24;
//

/// An error we can encounter when getting user info
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum LoginError {
/// Database error
DbError(sqlx::Error),
}

impl Display for LoginError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DbError(_) => write!(f, "database backend error"),
}
}
}

impl Error for LoginError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::DbError(x) => Some(x),
}
}
}

impl From<sqlx::Error> for LoginError {
fn from(value: sqlx::Error) -> Self {
Self::DbError(value)
}
#[error("database backend error")]
DbError(#[from] sqlx::Error),
}

//
Expand Down
Loading
Loading