From a8f1e2598676576746783231e2d826f527a404c2 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 1 Jul 2023 22:20:10 -0600 Subject: [PATCH] add error messages for gives --- src/views/HomeView.vue | 14 ++++++++++++-- src/views/ProjectViewView.vue | 26 ++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 29b7bc6..a31d1ec 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -296,6 +296,12 @@ export default class HomeView extends Vue { "You must select an identity before you can record a give."; return; } + if (!description && !hours) { + this.alertTitle = "Error"; + this.alertMessage = + "You must enter a description or some number of hours."; + return; + } const account = R.find( (acc) => acc.did === this.activeDid, this.allAccounts @@ -319,7 +325,8 @@ export default class HomeView extends Vue { console.log("Error with give result:", result); this.alertTitle = "Error"; this.alertMessage = - result.data?.message || "There was an error recording the give."; + result.data?.error?.message || + "There was an error recording the give."; } else { this.alertTitle = "Success"; this.alertMessage = "That gift was recorded."; @@ -327,10 +334,13 @@ export default class HomeView extends Vue { } }) .catch((e) => { + // axios throws errors on 400 responses console.log("Error with give caught:", e); this.alertTitle = "Error"; this.alertMessage = - e.userMessage || "There was an error recording the give."; + e.userMessage || + e.response?.data?.error?.message || + "There was an error recording the give."; }); } diff --git a/src/views/ProjectViewView.vue b/src/views/ProjectViewView.vue index d80964f..dc9c5a9 100644 --- a/src/views/ProjectViewView.vue +++ b/src/views/ProjectViewView.vue @@ -179,6 +179,18 @@ --> + + +
+ +

{{ alertTitle }}

+

{{ alertMessage }}

+
@@ -318,6 +330,12 @@ export default class ProjectViewView extends Vue { "You must select an identity before you can record a give."; return; } + if (!description && !hours) { + this.alertTitle = "Error"; + this.alertMessage = + "You must enter a description or some number of hours."; + return; + } const accounts = await accountsDB.accounts.toArray(); const account = R.find((acc) => acc.did === this.activeDid, accounts); const identity = JSON.parse(account?.identity || "null"); @@ -339,7 +357,8 @@ export default class ProjectViewView extends Vue { console.log("Error with give result:", result); this.alertTitle = "Error"; this.alertMessage = - result.data?.message || "There was an error recording the give."; + result.data?.error?.message || + "There was an error recording the give."; } else { this.alertTitle = "Success"; this.alertMessage = "That gift was recorded."; @@ -347,10 +366,13 @@ export default class ProjectViewView extends Vue { } }) .catch((e) => { + // axios throws errors on 400 responses console.log("Error with give caught:", e); this.alertTitle = "Error"; this.alertMessage = - e.userMessage || "There was an error recording the give."; + e.userMessage || + e.response?.data?.error?.message || + "There was an error recording the give."; }); }