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(
|
||||
socket: &UdpSocket,
|
||||
code: ErrorCode,
|
||||
msg: String,
|
||||
msg: &str,
|
||||
) -> 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`].
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ fn check_response(socket: &UdpSocket) -> Result<(), Box<dyn Error>> {
|
|||
Message::send_error(
|
||||
&socket,
|
||||
ErrorCode::IllegalOperation,
|
||||
"invalid oack response".to_string(),
|
||||
"invalid oack response",
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue