Skip to content

Commit

Permalink
Lesson 3 Homework - Replace an unwrap() with match select statement (0…
Browse files Browse the repository at this point in the history
  • Loading branch information
The1OneID authored Jul 30, 2022
1 parent c95de9c commit 4161831
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ol/cli/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{fs, io, path::PathBuf, process::Command, thread, time::Duration};
use tokio::time::interval;
use tokio_stream::wrappers::IntervalStream;
use warp::{sse::Event, Filter};
use std::process::exit;

use crate::{cache::Vitals, check::runner, node::node::Node};

Expand Down Expand Up @@ -39,10 +40,16 @@ pub async fn start_server(mut node: Node, _run_checks: bool) {

// TODO: re-assigning node_home because warp moves it.
let node_home = cfg.clone().workspace.node_home.clone();

let account_template = warp::path("account.json").and(warp::get()).map(move || {
let account_path = node_home.join("account.json");
fs::read_to_string(account_path).unwrap()
let account_file_name = "account.json";
let account_template = warp::path(account_file_name).and(warp::get()).map(move || {
let account_path = node_home.join(account_file_name);
match fs::read_to_string(account_path) {
Ok(value) => value,
Err(msg) => {
println!("Could not read {}: \nError {}", account_file_name, msg);
exit(1)
},
}
});

let node_home = cfg.clone().workspace.node_home.clone();
Expand Down

0 comments on commit 4161831

Please sign in to comment.