diff --git a/src/ear.rs b/src/ear.rs index 6ef6c54..5787b0a 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -7,6 +7,7 @@ use std::net::{TcpListener, TcpStream}; use urlencoding::decode; use crate::database; +use crate::database::DatabaseError; use crate::mouth::Mouth; #[derive(Debug)] @@ -68,8 +69,8 @@ impl Ear { Some(req) => req, None => continue, }; - let mut sender = Mouth::new(&stream); println!("Received request: {}", &req); + let mut sender = Mouth::new(&stream); match parse_uri(&req) { Ok(req) => handle_request(req, sender), @@ -174,7 +175,7 @@ fn handle_get_request(request: Request, mut sender: Mouth) { Err(err) => sender.send_internal_error(format!("{}", err)), }, _ => sender.send_bad_request(""), - } + }; } /// Handles a given POST request @@ -193,8 +194,8 @@ fn handle_post_request(request: Request, mut sender: Mouth) { sender.send_ok(format!("Favori inséré avec succès : {}", result.titre)) } Err(err) => match err { - database::DatabaseError::NotFound => sender.send_not_found(format!("{}", err)), - database::DatabaseError::FoundDuplicate => { + DatabaseError::NotFound => sender.send_not_found(format!("{}", err)), + DatabaseError::FoundDuplicate => { sender.send_bad_request(format!("{}", err).as_str()) } _ => sender.send_internal_error(format!("{}", err)),