major server rewrite now all working
This commit is contained in:
17
src/error.rs
17
src/error.rs
@@ -1,4 +1,6 @@
|
||||
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use json;
|
||||
use crate::server::proto;
|
||||
|
||||
@@ -19,11 +21,22 @@ impl MizeError {
|
||||
return data;
|
||||
}
|
||||
|
||||
pub fn to_message(self: MizeError) -> proto::Response {
|
||||
pub fn to_message(self: MizeError, origin: proto::Origin) -> proto::Message {
|
||||
let data = self.to_json();
|
||||
let mut msg = vec![crate::PROTO_VERSION, proto::MSG_ERROR];
|
||||
msg.extend(json::stringify(data).into_bytes());
|
||||
return proto::Response::One(msg);
|
||||
return proto::Message::from_bytes(msg, origin);
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FromUtf8Error> for MizeError {
|
||||
fn from(utf_err: FromUtf8Error) -> MizeError{
|
||||
let err = MizeError {
|
||||
code: 109,
|
||||
kind: "faulty_message".to_string(),
|
||||
message: "std::string::FromUtf8Error while parsing something from the message".to_string(),
|
||||
};
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user