Refactor for global error type
This commit is contained in:
@@ -14,4 +14,5 @@ emojis = "0.6.2"
|
||||
chrono = { version = "0.4.24", features = ["serde"] }
|
||||
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls", "mysql", "chrono" ] }
|
||||
dotenvy = "0.15"
|
||||
realm_auth = { path = "../auth" }
|
||||
realm_auth = { path = "../auth" }
|
||||
realm_shared = { path = "../shared" }
|
||||
@@ -3,8 +3,9 @@ use chrono::{DateTime, Utc};
|
||||
use sqlx::{Error, MySql, Pool, Row};
|
||||
use sqlx::mysql::MySqlRow;
|
||||
use tarpc::context::Context;
|
||||
use crate::types::{Edit, ErrorCode, Message, MessageData, Reaction, RealmChat, Redaction, Reply, Room, User};
|
||||
use crate::types::ErrorCode::*;
|
||||
use crate::types::{Edit, Message, MessageData, Reaction, RealmChat, Redaction, Reply, Room, User};
|
||||
use realm_shared::types::ErrorCode::*;
|
||||
use realm_shared::types::ErrorCode;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RealmChatServer {
|
||||
@@ -84,7 +85,7 @@ impl RealmChat for RealmChatServer {
|
||||
self.dbmessage_to_message(row)
|
||||
},
|
||||
Err(_) => {
|
||||
Err(NotFound)
|
||||
Err(MessageNotFound)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -122,7 +123,7 @@ impl RealmChat for RealmChatServer {
|
||||
|
||||
match result {
|
||||
Ok(row) => { self.dbroom_to_room(row) },
|
||||
Err(_) => Err(NotFound),
|
||||
Err(_) => Err(RoomNotFound),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ impl RealmChat for RealmChatServer {
|
||||
|
||||
match result {
|
||||
Ok(row) => { self.dbuser_to_user(row) },
|
||||
Err(_) => Err(NotFound),
|
||||
Err(_) => Err(UserNotFound),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ impl RealmChatServer {
|
||||
let admin_only_view: Result<bool, _> = row.try_get("admin_only_view");
|
||||
|
||||
if id.is_err() {
|
||||
return Err(FailedToUnwrapDB)
|
||||
return Err(MalformedDBResponse)
|
||||
}
|
||||
|
||||
Ok(Room {
|
||||
@@ -200,7 +201,7 @@ impl RealmChatServer {
|
||||
let admin: Result<bool, _> = row.try_get("admin");
|
||||
|
||||
if id.is_err() {
|
||||
return Err(FailedToUnwrapDB)
|
||||
return Err(MalformedDBResponse)
|
||||
}
|
||||
|
||||
Ok(User {
|
||||
@@ -220,7 +221,7 @@ impl RealmChatServer {
|
||||
};
|
||||
|
||||
if type_enum == "" {
|
||||
return Err(FailedToUnwrapDB)
|
||||
return Err(MalformedDBResponse)
|
||||
}
|
||||
|
||||
let id: u32 = row.try_get("message.id").unwrap();
|
||||
@@ -295,7 +296,7 @@ impl RealmChatServer {
|
||||
}),
|
||||
})
|
||||
}
|
||||
_ => { Err(FailedToUnwrapDB) }
|
||||
_ => { Err(MalformedDBResponse) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use tarpc::serde::{Deserialize, Serialize};
|
||||
use realm_shared::types::ErrorCode;
|
||||
|
||||
#[tarpc::service]
|
||||
pub trait RealmChat {
|
||||
async fn test(name: String) -> String;
|
||||
|
||||
|
||||
//TODO: Any user authorized as themselves
|
||||
async fn send_message(auth_token: String, message: Message) -> Result<Message, ErrorCode>;
|
||||
async fn start_typing(auth_token: String) -> ErrorCode;
|
||||
@@ -28,15 +29,6 @@ pub trait RealmChat {
|
||||
// unban user
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum ErrorCode {
|
||||
None,
|
||||
Error,
|
||||
Unauthorized,
|
||||
NotFound,
|
||||
FailedToUnwrapDB,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
pub id: u32,
|
||||
|
||||
Reference in New Issue
Block a user