Skip to content

Commit

Permalink
Crawling function now exits the function insted of the program on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Antosser committed May 22, 2023
1 parent b944af1 commit a71e29b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn crawl(
Ok(x) => x,
Err(e) => {
error!("Cannot request file: {}", e);
exit(1);
return;
}
};
let is_html = match response.headers().get("content-type") {
Expand Down Expand Up @@ -198,16 +198,19 @@ fn crawl(
break 'download;
}
trace!("Writing to file: {}", file_path);
let mut f = fs::File::create(file_path).unwrap_or_else(|e| {
error!("Cannot create file: {}: {}", file_path, e);
exit(1);
});
let mut f = match fs::File::create(file_path) {
Ok(x) => x,
Err(e) => {
error!("Cannot create file: {}: {}", file_path, e);
return;
}
};

match f.write_all(&response_bytes) {
Ok(_) => {}
Err(e) => {
error!("Cannot write to file: {}: {}", file_path, e);
exit(1);
return;
}
};
}
Expand Down

0 comments on commit a71e29b

Please sign in to comment.