Switch spaces to tabs

This commit is contained in:
Tobias Reisinger 2022-07-20 00:38:09 +02:00
parent 07aca5293e
commit 4261141c3a
17 changed files with 560 additions and 557 deletions
src/handlers

View file

@ -5,42 +5,42 @@ use serde::{Serialize, Serializer};
#[derive(Debug)]
pub enum HandlerError {
BadUid,
ProtectedSchedule,
BadUid,
ProtectedSchedule,
}
impl HandlerError {
fn get_code(&self) -> StatusCode {
match self {
HandlerError::BadUid => StatusCode::BAD_REQUEST,
HandlerError::ProtectedSchedule => StatusCode::FORBIDDEN,
}
}
fn get_code(&self) -> StatusCode {
match self {
HandlerError::BadUid => StatusCode::BAD_REQUEST,
HandlerError::ProtectedSchedule => StatusCode::FORBIDDEN,
}
}
}
impl Serialize for HandlerError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut s = serializer.serialize_struct("error", 2)?;
s.serialize_field("code", &self.get_code().as_u16())?;
s.serialize_field("description", &String::from(self))?;
s.end()
}
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut s = serializer.serialize_struct("error", 2)?;
s.serialize_field("code", &self.get_code().as_u16())?;
s.serialize_field("description", &String::from(self))?;
s.end()
}
}
impl From<&HandlerError> for String {
fn from(err: &HandlerError) -> Self {
match err {
HandlerError::BadUid => String::from("the uid is in a bad format"),
HandlerError::ProtectedSchedule => String::from("the targeted schedule is protected"),
}
}
fn from(err: &HandlerError) -> Self {
match err {
HandlerError::BadUid => String::from("the uid is in a bad format"),
HandlerError::ProtectedSchedule => String::from("the targeted schedule is protected"),
}
}
}
impl From<HandlerError> for HttpResponse {
fn from(err: HandlerError) -> Self {
HttpResponse::build(err.get_code()).json(err)
}
fn from(err: HandlerError) -> Self {
HttpResponse::build(err.get_code()).json(err)
}
}