Minor changes

This commit is contained in:
flyingscorpio@clevo 2023-01-10 21:12:42 +01:00
parent b0704f50a4
commit 2dea10ca62

View file

@ -7,6 +7,7 @@ use std::net::{TcpListener, TcpStream};
use urlencoding::decode; use urlencoding::decode;
use crate::database; use crate::database;
use crate::database::DatabaseError;
use crate::mouth::Mouth; use crate::mouth::Mouth;
#[derive(Debug)] #[derive(Debug)]
@ -68,8 +69,8 @@ impl Ear {
Some(req) => req, Some(req) => req,
None => continue, None => continue,
}; };
let mut sender = Mouth::new(&stream);
println!("Received request: {}", &req); println!("Received request: {}", &req);
let mut sender = Mouth::new(&stream);
match parse_uri(&req) { match parse_uri(&req) {
Ok(req) => handle_request(req, sender), 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)), Err(err) => sender.send_internal_error(format!("{}", err)),
}, },
_ => sender.send_bad_request(""), _ => sender.send_bad_request(""),
} };
} }
/// Handles a given POST 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)) sender.send_ok(format!("Favori inséré avec succès : {}", result.titre))
} }
Err(err) => match err { Err(err) => match err {
database::DatabaseError::NotFound => sender.send_not_found(format!("{}", err)), DatabaseError::NotFound => sender.send_not_found(format!("{}", err)),
database::DatabaseError::FoundDuplicate => { DatabaseError::FoundDuplicate => {
sender.send_bad_request(format!("{}", err).as_str()) sender.send_bad_request(format!("{}", err).as_str())
} }
_ => sender.send_internal_error(format!("{}", err)), _ => sender.send_internal_error(format!("{}", err)),