Error messages, less unwrap
This commit is contained in:
parent
f16343a93a
commit
710df5f6bc
@ -19,9 +19,15 @@ fn main() {
|
||||
args.next();
|
||||
let address = args.next().unwrap_or("127.0.0.1:8080".to_string());
|
||||
let listener = TcpListener::bind(address).unwrap();
|
||||
eprintln!("Strated server!");
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let stream = stream.unwrap();
|
||||
eprintln!("New connection!");
|
||||
|
||||
let Ok(stream) = stream else {
|
||||
eprintln!("Connection failed!");
|
||||
continue;
|
||||
};
|
||||
|
||||
context.handle_connection(stream);
|
||||
}
|
||||
@ -45,6 +51,7 @@ struct Context {
|
||||
impl Context {
|
||||
fn handle_connection(&mut self, mut stream: TcpStream) {
|
||||
let Some(request) = Request::from(&stream) else {
|
||||
eprintln!("Invalid request!");
|
||||
return;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user