Add token authentication for controllers

This commit is contained in:
Tobias Reisinger 2025-05-31 23:18:45 +02:00
commit e2dc5f8857
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 9 additions and 0 deletions

View file

@ -15,6 +15,7 @@ use crate::types::EmgauwaUid;
#[derive(Debug)]
pub enum EmgauwaError {
Api(ApiError),
Unauthorized(String),
Uid(uuid::Error),
Serialization(serde_json::Error),
Database(DatabaseError),
@ -28,6 +29,7 @@ impl EmgauwaError {
fn get_code(&self) -> StatusCode {
match self {
EmgauwaError::Api(err) => err.get_code(),
EmgauwaError::Unauthorized(_) => StatusCode::UNAUTHORIZED,
EmgauwaError::Serialization(_) => StatusCode::INTERNAL_SERVER_ERROR,
EmgauwaError::Database(err) => err.get_code(),
EmgauwaError::Uid(_) => StatusCode::BAD_REQUEST,
@ -43,6 +45,7 @@ impl From<&EmgauwaError> for String {
fn from(err: &EmgauwaError) -> Self {
match err {
EmgauwaError::Api(err) => String::from(err),
EmgauwaError::Unauthorized(_) => format!("unauthorized request: {}", err),
EmgauwaError::Serialization(_) => String::from("error during (de-)serialization"),
EmgauwaError::Database(err) => String::from(err),
EmgauwaError::Uid(_) => String::from("the uid is in a bad format"),