CompositeError, UserAuthRequired, /users/self & users/:id, misc

This commit is contained in:
2026-02-24 00:55:19 +01:00
parent 085764f06a
commit ee7ed48144
7 changed files with 164 additions and 19 deletions

View File

@@ -1,3 +1,7 @@
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use chrono::{DateTime, Duration, Utc};
use rusqlite::OptionalExtension;
use serde::{Deserialize, Serialize};
@@ -5,7 +9,7 @@ use sha2::{Digest, Sha256};
use uuid::Uuid;
use crate::{
database,
ISE_MSG, database,
users::{User, auth},
};
@@ -44,6 +48,19 @@ impl From<rusqlite::Error> for SessionError {
SessionError::DatabaseError(error.to_string())
}
}
impl IntoResponse for SessionError {
fn into_response(self) -> Response {
match self {
Self::DatabaseError(e) => {
eprintln!("[ERROR] Database error occured: {e}");
(StatusCode::INTERNAL_SERVER_ERROR, ISE_MSG.into())
}
Self::NoSessionWithId(_) => (StatusCode::BAD_REQUEST, self.to_string()),
Self::NoSessionWithToken(_) => (StatusCode::BAD_REQUEST, self.to_string()),
}
.into_response()
}
}
impl Session {
pub fn get_by_id(id: Uuid) -> Result<Session, SessionError> {