diff --git a/crates/bonfire/src/websocket.rs b/crates/bonfire/src/websocket.rs index a706080b4..810befbf9 100644 --- a/crates/bonfire/src/websocket.rs +++ b/crates/bonfire/src/websocket.rs @@ -79,7 +79,9 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr) // Try to authenticate the user. let Some(token) = config.get_session_token().as_ref() else { write - .send(config.encode(&create_error!(InvalidSession))) + .send(config.encode(&EventV1::Error { + data: create_error!(InvalidSession), + })) .await .ok(); return; @@ -88,7 +90,10 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr) let (user, session_id) = match User::from_token(db, token, UserHint::Any).await { Ok(user) => user, Err(err) => { - write.send(config.encode(&err)).await.ok(); + write + .send(config.encode(&EventV1::Error { data: err })) + .await + .ok(); return; } }; diff --git a/crates/core/database/src/events/client.rs b/crates/core/database/src/events/client.rs index 4dea42153..b35007cc3 100644 --- a/crates/core/database/src/events/client.rs +++ b/crates/core/database/src/events/client.rs @@ -1,4 +1,5 @@ use authifier::AuthifierEvent; +use revolt_result::Error; use serde::{Deserialize, Serialize}; use revolt_models::v0::{ @@ -7,22 +8,9 @@ use revolt_models::v0::{ PartialChannel, PartialMember, PartialMessage, PartialRole, PartialServer, PartialUser, PartialWebhook, RemovalIntention, Report, Server, User, UserSettings, Webhook, }; -use revolt_result::Error; use crate::Database; -/// WebSocket Client Errors -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(tag = "error")] -pub enum WebSocketError { - LabelMe, - InternalError { at: String }, - InvalidSession, - OnboardingNotFinished, - AlreadyAuthenticated, - MalformedData { msg: String }, -} - /// Ping Packet #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] @@ -31,14 +19,6 @@ pub enum Ping { Number(usize), } -/// Untagged Error -#[derive(Serialize)] -#[serde(untagged)] -pub enum ErrorEvent { - Error(WebSocketError), - APIError(Error), -} - /// Fields provided in Ready payload #[derive(PartialEq)] pub enum ReadyPayloadFields { @@ -58,6 +38,8 @@ pub enum ReadyPayloadFields { pub enum EventV1 { /// Multiple events Bulk { v: Vec }, + /// Error event + Error { data: Error }, /// Successfully authenticated Authenticated,