From dad726c4025bb58838f01dc8f8a91afe4e544beb Mon Sep 17 00:00:00 2001 From: Mengling Ding Date: Wed, 21 Aug 2024 17:27:53 -0500 Subject: [PATCH] feat: pass the client errors to cfm-webui --- pkg/api/api_default_service.go | 7 +---- pkg/common/parameters.go | 5 --- .../Appliance/ComposeMemoryButton.vue | 4 +-- webui/src/components/Appliance/Memory.vue | 2 +- webui/src/components/Stores/ApplianceStore.ts | 21 +++++++++++-- .../src/components/Stores/BladeMemoryStore.ts | 31 +++++++++++++++++-- webui/src/components/Stores/BladeStore.ts | 31 +++++++++++++++++-- webui/src/components/Stores/HostStore.ts | 31 +++++++++++++++++-- 8 files changed, 106 insertions(+), 26 deletions(-) diff --git a/pkg/api/api_default_service.go b/pkg/api/api_default_service.go index 1b3aaec..5d489e7 100644 --- a/pkg/api/api_default_service.go +++ b/pkg/api/api_default_service.go @@ -235,12 +235,7 @@ func (cfm *CfmApiService) BladesComposeMemory(ctx context.Context, applianceId s memory, err := blade.ComposeMemory(ctx, &r) if err != nil { if memory != nil { - // Use the custom response structure to pass both the memory and partial error to the frontend. - customResponse := common.CustomResponse{ - Data: memory, - Error: err.Error(), - } - return openapi.Response(http.StatusPartialContent, customResponse), nil + return openapi.Response(http.StatusPartialContent, memory), nil } else { return formatErrorResp(ctx, err.(*common.RequestError)) } diff --git a/pkg/common/parameters.go b/pkg/common/parameters.go index 0c502aa..533c96e 100644 --- a/pkg/common/parameters.go +++ b/pkg/common/parameters.go @@ -34,11 +34,6 @@ type Settings struct { HostIpOverride string // An user override option for the host server Ip address } -type CustomResponse struct { - Data interface{} `json:"data,omitempty"` - Error string `json:"error,omitempty"` -} - const ( KeyVerbosity = "cfmCtxVerbosity" KeyBackend = "cfmCtxBackend" diff --git a/webui/src/components/Appliance/ComposeMemoryButton.vue b/webui/src/components/Appliance/ComposeMemoryButton.vue index 48232fc..5d4b91f 100644 --- a/webui/src/components/Appliance/ComposeMemoryButton.vue +++ b/webui/src/components/Appliance/ComposeMemoryButton.vue @@ -153,8 +153,6 @@ >

Compose memory failed!

- Error Message: -
{{ composeMemoryError }}

@@ -269,7 +267,7 @@ export default { }, qoSs: [Qos.NUMBER_1, Qos.NUMBER_2, Qos.NUMBER_4, Qos.NUMBER_8], showQoS: Qos.NUMBER_1, - showPort: "", + showPort: "port0", partialSuccess: "", newMemoryId: "", // Be used on success popup diff --git a/webui/src/components/Appliance/Memory.vue b/webui/src/components/Appliance/Memory.vue index 130033c..62d7c32 100644 --- a/webui/src/components/Appliance/Memory.vue +++ b/webui/src/components/Appliance/Memory.vue @@ -294,7 +294,7 @@ >

Free memory failed!

- Error: {{ this.freeMemoryError }} + {{ this.freeMemoryError }}

diff --git a/webui/src/components/Stores/ApplianceStore.ts b/webui/src/components/Stores/ApplianceStore.ts index 2d21f0f..39ef5b4 100644 --- a/webui/src/components/Stores/ApplianceStore.ts +++ b/webui/src/components/Stores/ApplianceStore.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { Appliance, Credentials, DefaultApi } from "@/axios/api"; import { BASE_PATH } from "@/axios/base"; +import axios from 'axios'; // Use API_BASE_PATH to overwrite the BASE_PATH in the generated client code const API_BASE_PATH = process.env.BASE_PATH || BASE_PATH; @@ -69,7 +70,15 @@ export const useApplianceStore = defineStore('appliance', { this.appliances.push(addedAppliance); return addedAppliance; } catch (error) { - this.addApplianceError = error; + if (axios.isAxiosError(error)) { + this.addApplianceError = error.message; + if (error.response) { + this.addApplianceError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.addApplianceError = error; + } console.error("Error:", error); } }, @@ -89,7 +98,15 @@ export const useApplianceStore = defineStore('appliance', { } return deletedAppliance; } catch (error) { - this.deleteApplianceError = error; + if (axios.isAxiosError(error)) { + this.deleteApplianceError = error.message; + if (error.response) { + this.deleteApplianceError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.deleteApplianceError = error; + } console.error("Error:", error); } }, diff --git a/webui/src/components/Stores/BladeMemoryStore.ts b/webui/src/components/Stores/BladeMemoryStore.ts index 1810fd3..d9c01f5 100644 --- a/webui/src/components/Stores/BladeMemoryStore.ts +++ b/webui/src/components/Stores/BladeMemoryStore.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { MemoryRegion, DefaultApi, ComposeMemoryRequest, AssignMemoryRequest } from "@/axios/api"; import { BASE_PATH } from "@/axios/base"; +import axios from 'axios'; // Use API_BASE_PATH to overwrite the BASE_PATH in the generated client code const API_BASE_PATH = process.env.BASE_PATH || BASE_PATH; @@ -63,7 +64,15 @@ export const useBladeMemoryStore = defineStore('bladeMemory', { this.bladeMemory.push(newMemory); return newMemory; } catch (error) { - this.composeMemoryError = error; + if (axios.isAxiosError(error)) { + this.composeMemoryError = error.message; + if (error.response) { + this.composeMemoryError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.composeMemoryError = error; + } console.error("Error:", error); } }, @@ -79,7 +88,15 @@ export const useBladeMemoryStore = defineStore('bladeMemory', { ); return response; } catch (error) { - this.assignOrUnassignMemoryError = error; + if (axios.isAxiosError(error)) { + this.assignOrUnassignMemoryError = error.message; + if (error.response) { + this.assignOrUnassignMemoryError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.assignOrUnassignMemoryError = error; + } console.error("Error assign or unassign memory:", error); } }, @@ -100,7 +117,15 @@ export const useBladeMemoryStore = defineStore('bladeMemory', { } return response; } catch (error) { - this.freeMemoryError = error; + if (axios.isAxiosError(error)) { + this.freeMemoryError = error.message; + if (error.response) { + this.freeMemoryError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.freeMemoryError = error; + } console.error("Error free memory:", error); } } diff --git a/webui/src/components/Stores/BladeStore.ts b/webui/src/components/Stores/BladeStore.ts index bb1e57f..59fcafe 100644 --- a/webui/src/components/Stores/BladeStore.ts +++ b/webui/src/components/Stores/BladeStore.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { Blade, Credentials, DefaultApi } from "@/axios/api"; import { BASE_PATH } from "@/axios/base"; +import axios from 'axios'; // Use API_BASE_PATH to overwrite the BASE_PATH in the generated client code const API_BASE_PATH = process.env.BASE_PATH || BASE_PATH; @@ -75,7 +76,15 @@ export const useBladeStore = defineStore('blade', { const resyncedBlade = response.data; return resyncedBlade; } catch (error) { - this.resyncBladeError = error; + if (axios.isAxiosError(error)) { + this.resyncBladeError = error.message; + if (error.response) { + this.resyncBladeError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.resyncBladeError = error; + } console.error("Error:", error); } }, @@ -94,7 +103,15 @@ export const useBladeStore = defineStore('blade', { this.blades.push(newBlade); return newBlade; } catch (error) { - this.addBladeError = error; + if (axios.isAxiosError(error)) { + this.addBladeError = error.message; + if (error.response) { + this.addBladeError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.addBladeError = error; + } console.error("Error:", error); } }, @@ -114,7 +131,15 @@ export const useBladeStore = defineStore('blade', { } return deletedBlade; } catch (error) { - this.deleteBladeError = error; + if (axios.isAxiosError(error)) { + this.deleteBladeError = error.message; + if (error.response) { + this.deleteBladeError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.deleteBladeError = error; + } console.error("Error:", error); } }, diff --git a/webui/src/components/Stores/HostStore.ts b/webui/src/components/Stores/HostStore.ts index 4caadfe..daf649d 100644 --- a/webui/src/components/Stores/HostStore.ts +++ b/webui/src/components/Stores/HostStore.ts @@ -2,6 +2,7 @@ import { defineStore } from 'pinia' import { Host, Credentials, DefaultApi } from "@/axios/api"; import { BASE_PATH } from "@/axios/base"; +import axios from 'axios'; // Use API_BASE_PATH to overwrite the BASE_PATH in the generated client code const API_BASE_PATH = process.env.BASE_PATH || BASE_PATH; @@ -59,7 +60,15 @@ export const useHostStore = defineStore('host', { this.hosts.push(addedHost); return addedHost; } catch (error) { - this.addHostError = error; + if (axios.isAxiosError(error)) { + this.addHostError = error.message; + if (error.response) { + this.addHostError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.addHostError = error; + } console.error("Error:", error); } }, @@ -79,7 +88,15 @@ export const useHostStore = defineStore('host', { } return deletedHost; } catch (error) { - this.deleteHostError = error; + if (axios.isAxiosError(error)) { + this.deleteHostError = error.message; + if (error.response) { + this.deleteHostError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.deleteHostError = error; + } console.error("Error:", error); } }, @@ -93,7 +110,15 @@ export const useHostStore = defineStore('host', { const resyncedHost = response.data; return resyncedHost; } catch (error) { - this.resyncHostError = error; + if (axios.isAxiosError(error)) { + this.resyncHostError = error.message; + if (error.response) { + this.resyncHostError = error.response?.data.status.message + " (" + error.message + ")"; + } + } + else { + this.resyncHostError = error; + } console.error("Error:", error); } },