map the response of the ws.send call into a LuaError

This commit is contained in:
AsynchronousMatrix 2023-07-19 12:48:54 +01:00
parent 4ed7cafc77
commit e5a844ecec

View file

@ -154,20 +154,20 @@ where
{
let mut ws = socket.write_stream.lock().await;
let _ = ws
.send(WsMessage::Close(Some(WsCloseFrame {
code: match code {
Some(code) if (1000..=4999).contains(&code) => WsCloseCode::from(code),
Some(code) => {
return Err(LuaError::RuntimeError(format!(
"Close code must be between 1000 and 4999, got {code}"
)))
}
None => WsCloseCode::Normal,
},
reason: "".into(),
})))
.await;
ws.send(WsMessage::Close(Some(WsCloseFrame {
code: match code {
Some(code) if (1000..=4999).contains(&code) => WsCloseCode::from(code),
Some(code) => {
return Err(LuaError::RuntimeError(format!(
"Close code must be between 1000 and 4999, got {code}"
)))
}
None => WsCloseCode::Normal,
},
reason: "".into(),
})))
.await
.map_err(LuaError::external)?;
let res = ws.close();
res.await.map_err(LuaError::external)