From 2998957617cd49dbd6bd5969d44a7e11bc51c739 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 b1d4f138..f26ae0ec 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 867cfd81..b1da9882 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 33c63c89..c8d888be 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 9d02dd86..221c9211 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 5c3ff6d2..ba5cc6ad 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 ac60ba74..64687a3d 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 9f16edb5..6bf4164f 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 dd651092..e03f1ff7 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 849822af..18ba98c9 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 677007ca..ebc7d7b7 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 931ced2d..f57d8913 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 c8627845..13b4d2ea 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 18b5d341..604c2617 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 26475a38..25cfadef 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 09129d67..1475de6b 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 bd954d20..cd3961b5 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; }