From efddac5e9500f5572f653264722415ab820a7fc2 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Tue, 8 Feb 2022 15:57:42 -0500 Subject: [PATCH] Handle failure to bind --- src/server.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/server.rs b/src/server.rs index ae588a6..565e692 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; use std::io::Cursor; +use std::process::exit; use tiny_http::Header; use tiny_http::Request; @@ -12,7 +13,13 @@ use tiny_http::StatusCode; /// Runs the server in a single thread, bound to 0.0.0.0 on the provided port. Requests are /// handled first-come, first-serve pub fn go(domains: &[&str], port: u16) { - let server = Server::http(("0.0.0.0", port)).unwrap(); + let server = match Server::http(("0.0.0.0", port)) { + Ok(s) => s, + Err(e) => { + eprintln!("Couldn't create server on 0.0.0.0:{port}\n{e}"); + exit(1004); + } + }; println!("Running on 0.0.0.0:{port}");