From aa5a911edc9d78cb0c462bbd525287e0f3a122ec Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 25 Jan 2020 09:58:53 -0500 Subject: [PATCH] Fixing front end error messages. Fixes #462 --- server/src/websocket/server.rs | 1 + ui/src/components/communities.tsx | 2 +- ui/src/components/community-form.tsx | 2 +- ui/src/components/community.tsx | 2 +- ui/src/components/inbox.tsx | 2 +- ui/src/components/login.tsx | 2 +- ui/src/components/main.tsx | 2 +- ui/src/components/modlog.tsx | 2 +- ui/src/components/navbar.tsx | 4 ++-- ui/src/components/post-form.tsx | 2 +- ui/src/components/post.tsx | 2 +- ui/src/components/private-message-form.tsx | 2 +- ui/src/components/search.tsx | 2 +- ui/src/components/setup.tsx | 2 +- ui/src/components/user.tsx | 4 ++-- ui/src/interfaces.ts | 5 ++--- 16 files changed, 19 insertions(+), 19 deletions(-) diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index b1d4f1387..f26ae0ec3 100644 --- a/server/src/websocket/server.rs +++ b/server/src/websocket/server.rs @@ -291,6 +291,7 @@ impl Handler for ChatServer { Err(e) => e.to_string(), }; + println!("Message Sent: {}", msg_out); MessageResult(msg_out) } } diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx index 867cfd818..b1da98827 100644 --- a/ui/src/components/communities.tsx +++ b/ui/src/components/communities.tsx @@ -235,7 +235,7 @@ export class Communities extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.ListCommunities) { diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 33c63c897..c8d888be4 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -261,7 +261,7 @@ export class CommunityForm extends Component< parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); console.log(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state.loading = false; this.setState(this.state); diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index 9d02dd866..221c9211e 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -258,7 +258,7 @@ export class Community extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.context.router.history.push('/'); return; diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index 5c3ff6d2b..ba5cc6ad5 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -324,7 +324,7 @@ export class Inbox extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.GetReplies) { diff --git a/ui/src/components/login.tsx b/ui/src/components/login.tsx index ac60ba74b..64687a3d8 100644 --- a/ui/src/components/login.tsx +++ b/ui/src/components/login.tsx @@ -295,7 +295,7 @@ export class Login extends Component { parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state = this.emptyState; this.setState(this.state); diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 9f16edb5d..6bf4164ff 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -566,7 +566,7 @@ export class Main extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.GetFollowedCommunities) { diff --git a/ui/src/components/modlog.tsx b/ui/src/components/modlog.tsx index dd6510928..e03f1ff75 100644 --- a/ui/src/components/modlog.tsx +++ b/ui/src/components/modlog.tsx @@ -425,7 +425,7 @@ export class Modlog extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.GetModlog) { diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index 849822af1..18ba98c92 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -202,8 +202,8 @@ export class Navbar extends Component { parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); - if (res.error) { - if (res.error == 'not_logged_in') { + if (msg.error) { + if (msg.error == 'not_logged_in') { UserService.Instance.logout(); location.reload(); } diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 677007caf..ebc7d7b76 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -475,7 +475,7 @@ export class PostForm extends Component { parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state.loading = false; this.setState(this.state); diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 931ced2d1..f57d89137 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -345,7 +345,7 @@ export class Post extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.GetPost) { diff --git a/ui/src/components/private-message-form.tsx b/ui/src/components/private-message-form.tsx index c8627845d..13b4d2eab 100644 --- a/ui/src/components/private-message-form.tsx +++ b/ui/src/components/private-message-form.tsx @@ -283,7 +283,7 @@ export class PrivateMessageForm extends Component< parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state.loading = false; this.setState(this.state); diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index 18b5d3419..604c26173 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -479,7 +479,7 @@ export class Search extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); return; } else if (res.op == UserOperation.Search) { diff --git a/ui/src/components/setup.tsx b/ui/src/components/setup.tsx index 26475a387..25cfadef1 100644 --- a/ui/src/components/setup.tsx +++ b/ui/src/components/setup.tsx @@ -188,7 +188,7 @@ export class Setup extends Component { parseMessage(msg: WebSocketJsonResponse) { let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state.userLoading = false; this.setState(this.state); diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index 09129d67c..1475de6b2 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -1016,12 +1016,12 @@ export class User extends Component { parseMessage(msg: WebSocketJsonResponse) { console.log(msg); let res = wsJsonToRes(msg); - if (res.error) { + if (msg.error) { toast(i18n.t(msg.error), 'danger'); this.state.deleteAccountLoading = false; this.state.avatarLoading = false; this.state.userSettingsLoading = false; - if (res.error == 'couldnt_find_that_username_or_email') { + if (msg.error == 'couldnt_find_that_username_or_email') { this.context.router.history.push('/'); } this.setState(this.state); diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index bd954d20a..cd3961b5f 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -784,11 +784,10 @@ type ResponseType = export interface WebSocketResponse { op: UserOperation; data: ResponseType; - error?: string; } export interface WebSocketJsonResponse { - op: string; - data: ResponseType; + op?: string; + data?: ResponseType; error?: string; }