more user friendly server error msg

This commit is contained in:
Lev Kokotov
2022-02-07 11:15:33 -08:00
committed by Lev Kokotov
parent 290015957b
commit ef2aab3c61

View File

@@ -86,10 +86,8 @@ impl Server {
md5_password(&mut stream, user, password, &salt[..]).await?; md5_password(&mut stream, user, password, &salt[..]).await?;
} }
// We're in! // Authentication handshake complete.
0 => { 0 => (),
println!(">> Server authentication successful!");
}
_ => { _ => {
println!(">> Unsupported authentication mechanism: {}", code); println!(">> Unsupported authentication mechanism: {}", code);
@@ -99,7 +97,23 @@ impl Server {
} }
'E' => { 'E' => {
println!(">> Database error"); let error_code = match stream.read_u8().await {
Ok(error_code) => error_code,
Err(_) => return Err(Error::SocketError),
};
match error_code {
0 => (), // Terminator
_ => {
let mut error = vec![0u8; len as usize - 4 - 1];
match stream.read_exact(&mut error).await {
Ok(_) => (),
Err(_) => return Err(Error::SocketError),
};
println!(">> Server error: {}", String::from_utf8_lossy(&error));
}
};
return Err(Error::ServerError); return Err(Error::ServerError);
} }