Avoid baking error reasons into protocol
This commit is contained in:
parent
0e6acdbff4
commit
620285d1d1
2 changed files with 23 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ use crate::{Message, MessageId, User};
|
|||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct HelloCmd {
|
||||
pub room: String,
|
||||
pub nick: String,
|
||||
pub identity: String,
|
||||
}
|
||||
|
|
@ -17,8 +18,15 @@ pub enum HelloRpl {
|
|||
others: Vec<User>,
|
||||
last_message: MessageId,
|
||||
},
|
||||
NickTooLong,
|
||||
IdentityTooLong,
|
||||
InvalidRoom {
|
||||
reason: String,
|
||||
},
|
||||
InvalidNick {
|
||||
reason: String,
|
||||
},
|
||||
InvalidIdentity {
|
||||
reason: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
@ -30,7 +38,7 @@ pub struct NickCmd {
|
|||
#[serde(tag = "type")]
|
||||
pub enum NickRpl {
|
||||
Success,
|
||||
NickTooLong,
|
||||
InvalidNick { reason: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
@ -43,8 +51,8 @@ pub struct SendCmd {
|
|||
#[serde(tag = "type")]
|
||||
pub enum SendRpl {
|
||||
Success { message: Message },
|
||||
NickTooLong,
|
||||
ContentTooLong,
|
||||
InvalidNick { reason: String },
|
||||
InvalidContent { reason: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ async fn main() {
|
|||
serde_json::to_string_pretty(&Packet::Cmd {
|
||||
id: 12345,
|
||||
cmd: Cmd::Hello(HelloCmd {
|
||||
room: "welcome".to_string(),
|
||||
nick: "Garmy".to_string(),
|
||||
identity: "random garbage".to_string()
|
||||
})
|
||||
|
|
@ -47,7 +48,9 @@ async fn main() {
|
|||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Rpl {
|
||||
id: 67890,
|
||||
rpl: Rpl::Hello(HelloRpl::NickTooLong)
|
||||
rpl: Rpl::Hello(HelloRpl::InvalidNick {
|
||||
reason: "foo".to_string()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
|
|
@ -73,7 +76,9 @@ async fn main() {
|
|||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Rpl {
|
||||
id: 67890,
|
||||
rpl: Rpl::Nick(NickRpl::NickTooLong)
|
||||
rpl: Rpl::Nick(NickRpl::InvalidNick {
|
||||
reason: "foo".to_string()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
|
|
@ -103,7 +108,9 @@ async fn main() {
|
|||
"{}",
|
||||
serde_json::to_string_pretty(&Packet::Rpl {
|
||||
id: 67890,
|
||||
rpl: Rpl::Send(SendRpl::ContentTooLong)
|
||||
rpl: Rpl::Send(SendRpl::InvalidContent {
|
||||
reason: "foo".to_string()
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue