Restructure sending error
This commit is contained in:
parent
9f0dfe6073
commit
9e83591bae
2 changed files with 15 additions and 4 deletions
|
|
@ -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`].
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue