Handle failure to bind

This commit is contained in:
Emi Simpson 2022-02-08 15:57:42 -05:00
parent 8b30a7241d
commit efddac5e95
Signed by untrusted user: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 8 additions and 1 deletions

View File

@ -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}");