improve error messages
This commit is contained in:
parent
c765db8148
commit
eab99012e8
1 changed files with 11 additions and 6 deletions
17
src/main.rs
17
src/main.rs
|
@ -98,16 +98,20 @@ env!("CARGO_PKG_VERSION"));
|
|||
if !address.contains(":") { address.push_str(":25565"); }
|
||||
match address.to_socket_addrs() {
|
||||
Err(_) => {
|
||||
response.set_header("Content-Type", "text/html".to_string());
|
||||
response.status(StatusCode::BadRequest);
|
||||
response.body("Server address is invalid or unreachable.\n".to_string());
|
||||
return response.send();
|
||||
query_response = format!(
|
||||
"<hr/>
|
||||
<h2>Server Details</h2>
|
||||
<pre><code>Invalid server address: {}.</pre></code>",
|
||||
sanitize_html(&address.to_string()),
|
||||
);
|
||||
}
|
||||
Ok(mut addrs_iter) => {
|
||||
let address = addrs_iter.next().unwrap();
|
||||
|
||||
match MinecraftStatus::fetch(address) {
|
||||
Err(_) => {
|
||||
response.status(StatusCode::InternalServerError);
|
||||
query_response = format!(
|
||||
"<hr/>
|
||||
<h2>Server Details</h2>
|
||||
|
@ -150,6 +154,7 @@ env!("CARGO_PKG_VERSION"));
|
|||
None => { "mcq.bliss.town" }
|
||||
Some(host) => { host }
|
||||
});
|
||||
response.set_header("Content-Type", "text/html".to_string());
|
||||
response.body(response_content.to_string());
|
||||
return response.send();
|
||||
}
|
||||
|
@ -166,7 +171,7 @@ env!("CARGO_PKG_VERSION"));
|
|||
if !address.contains(":") { address.push_str(":25565"); }
|
||||
match address.to_socket_addrs() {
|
||||
Err(_) => {
|
||||
response.status(StatusCode::InternalServerError);
|
||||
response.status(StatusCode::BadRequest);
|
||||
response.body("Invalid server address.\n".to_string());
|
||||
}
|
||||
Ok(mut addrs_iter) => {
|
||||
|
@ -187,9 +192,9 @@ env!("CARGO_PKG_VERSION"));
|
|||
|
||||
match serde_json::to_string(&minecraft_status) {
|
||||
Err(e) => {
|
||||
eprintln!("Failed to parse status for {address}: {e}");
|
||||
eprintln!("Failed to format response from {} to JSON: {}", address, e);
|
||||
response.status(StatusCode::InternalServerError);
|
||||
response.body(format!("Failed to parse response from {address}.\n"));
|
||||
response.body("Internal Server Error\n".to_string());
|
||||
}
|
||||
Ok(json) => {
|
||||
response.status(StatusCode::OK);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue