Add saving periods
This commit is contained in:
parent
12d57d020f
commit
483fd60daa
13 changed files with 271 additions and 52 deletions
src/db
|
@ -4,6 +4,16 @@ use serde::{Serialize, Serializer};
|
|||
pub enum DatabaseError {
|
||||
InsertError,
|
||||
InsertGetError,
|
||||
NotFound,
|
||||
}
|
||||
|
||||
impl DatabaseError {
|
||||
fn to_code(&self) -> u32 {
|
||||
match self {
|
||||
DatabaseError::NotFound => 404,
|
||||
_ => 500
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for DatabaseError {
|
||||
|
@ -11,8 +21,9 @@ impl Serialize for DatabaseError {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_struct("error", 2)?;
|
||||
s.serialize_field("code", &500)?;
|
||||
let mut s = serializer.serialize_struct("error", 3)?;
|
||||
s.serialize_field("type", "database-error")?;
|
||||
s.serialize_field("code", &self.to_code())?;
|
||||
s.serialize_field("description", &String::from(self))?;
|
||||
s.end()
|
||||
}
|
||||
|
@ -25,6 +36,7 @@ impl From<&DatabaseError> for String {
|
|||
DatabaseError::InsertGetError => {
|
||||
String::from("error retrieving new entry from database (your entry was saved)")
|
||||
}
|
||||
DatabaseError::NotFound => String::from("model was not found in database")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue