Restructure sending error

This commit is contained in:
Altuğ Bakan 2023-03-29 11:52:04 +00:00
parent 9f0dfe6073
commit 9e83591bae
2 changed files with 15 additions and 4 deletions

View file

@ -55,11 +55,22 @@ impl Message {
pub fn send_error( pub fn send_error(
socket: &UdpSocket, socket: &UdpSocket,
code: ErrorCode, code: ErrorCode,
msg: String, msg: &str,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
socket.send(&Packet::Error { code, msg }.serialize()?)?; if socket
.send(
&Packet::Error {
code,
msg: msg.to_string(),
}
.serialize()?,
)
.is_err()
{
eprintln!("could not send an error message");
};
Ok(()) Err(msg.into())
} }
/// Sends an error packet to the supplied [`SocketAddr`]. /// Sends an error packet to the supplied [`SocketAddr`].

View file

@ -231,7 +231,7 @@ fn check_response(socket: &UdpSocket) -> Result<(), Box<dyn Error>> {
Message::send_error( Message::send_error(
&socket, &socket,
ErrorCode::IllegalOperation, ErrorCode::IllegalOperation,
"invalid oack response".to_string(), "invalid oack response",
)?; )?;
} }
} }