Skip to content

Commit 5af9bb3

Browse files
fix: Fixed internal error handling
1 parent c4df92a commit 5af9bb3

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mc-oauth"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2021"
55

66
[dependencies]

src/client.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bytes::{BufMut, BytesMut};
1919
use cfb8::Encryptor;
2020
use std::{sync::Arc, time::Duration};
2121
use tokio::net::TcpStream;
22-
use tracing::{debug, info};
22+
use tracing::{debug, error, info};
2323
use uuid::Uuid;
2424

2525
#[derive(Debug)]
@@ -77,7 +77,17 @@ impl MinecraftClient {
7777
}
7878
}
7979

80-
pub async fn run(&mut self) -> Result<()> {
80+
pub async fn run(&mut self) {
81+
match self._run().await {
82+
Ok(_) => info!(
83+
"Connection from {:?} closed successfully",
84+
self.stream.peer_addr().unwrap()
85+
),
86+
Err(e) => error!("Internal error occurred: {}", e),
87+
}
88+
}
89+
90+
pub async fn _run(&mut self) -> Result<()> {
8191
loop {
8292
let mut temp_buf = vec![0; 1024];
8393
self.stream.readable().await?;

src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,10 @@ async fn main() -> anyhow::Result<()> {
9797

9898
tokio::spawn(async move {
9999
// Setting client timeout
100-
match timeout(
100+
timeout(
101101
Duration::from_secs(config.server.timeout),
102102
client.run()
103-
).await {
104-
Ok(_) => info!("Connection from {} closed", addr),
105-
Err(e) => error!("Client exceptionally closed connection: {}", e)
106-
}
103+
).await.unwrap_or_else(|_| {error!("Connection from {} has been timed out", addr);})
107104
});
108105
},
109106
Err(e) => {

0 commit comments

Comments
 (0)