From 6d2df4a50c42404ad965af0942efdf9e50de2148 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Wed, 1 Nov 2023 08:56:22 -0600 Subject: [PATCH] fix the error message on a successful result --- src/views/HomeView.vue | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index b938062..e00bf61 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -524,15 +524,18 @@ export default class HomeView extends Vue { hours, ); - if (this.isGiveCreationError(result)) { + if ( + result.type === "error" || + this.isGiveCreationError(result.response) + ) { const errorMessage = this.getGiveCreationErrorMessage(result); - console.log("Error with give result:", result); + console.log("Error with give creation result:", result); this.$notify( { group: "alert", type: "danger", title: "Error", - text: errorMessage || "There was an error recording the give.", + text: errorMessage || "There was an error creating the give.", }, -1, ); @@ -549,7 +552,7 @@ export default class HomeView extends Vue { } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - console.log("Error with give caught:", error); + console.log("Error with give recordation caught:", error); const message = error.userMessage || error.response?.data?.error?.message || @@ -568,14 +571,26 @@ export default class HomeView extends Vue { // Helper functions for readability + /** + * @param result response "data" from the server + * @returns true if the result indicates an error + */ // eslint-disable-next-line @typescript-eslint/no-explicit-any isGiveCreationError(result: any) { return result.status !== 201 || result.data?.error; } + /** + * @param result direct response from the server (potentially with embedded "data") + * @returns best guess at an error message + */ // eslint-disable-next-line @typescript-eslint/no-explicit-any getGiveCreationErrorMessage(result: any) { - return result.data?.error?.message; + return ( + result.error?.userMessage || + result.error?.error || + result.data?.error?.message + ); } }