Add saving periods
This commit is contained in:
parent
12d57d020f
commit
483fd60daa
13 changed files with 271 additions and 52 deletions
src/handlers
34
src/handlers/errors.rs
Normal file
34
src/handlers/errors.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use serde::ser::SerializeStruct;
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
pub enum HandlerError {
|
||||
BadUidError,
|
||||
}
|
||||
|
||||
impl HandlerError {
|
||||
fn to_code(&self) -> u32 {
|
||||
match self {
|
||||
HandlerError::BadUidError => 400
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.to_code())?;
|
||||
s.serialize_field("description", &String::from(self))?;
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&HandlerError> for String {
|
||||
fn from(err: &HandlerError) -> Self {
|
||||
match err {
|
||||
HandlerError::BadUidError => String::from("the uid is in a bad format"),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue