Skip to content

Commit

Permalink
feat: pass the client errors to cfm-webui
Browse files Browse the repository at this point in the history
  • Loading branch information
Meng-20 committed Aug 21, 2024
1 parent c9f28a1 commit dad726c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 26 deletions.
7 changes: 1 addition & 6 deletions pkg/api/api_default_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/common/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions webui/src/components/Appliance/ComposeMemoryButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@
></v-icon>
<h2 class="text-h5 mb-6">Compose memory failed!</h2>
<p class="mb-4 text-medium-emphasis text-body-2">
Error Message:
<br />
{{ composeMemoryError }}
</p>
<v-divider class="mb-4"></v-divider>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/Appliance/Memory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
></v-icon>
<h2 class="text-h5 mb-6">Free memory failed!</h2>
<p class="mb-4 text-medium-emphasis text-body-2">
Error: {{ this.freeMemoryError }}
{{ this.freeMemoryError }}
</p>
<v-divider class="mb-4"></v-divider>
<div class="text-end">
Expand Down
21 changes: 19 additions & 2 deletions webui/src/components/Stores/ApplianceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
},
Expand All @@ -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);
}
},
Expand Down
31 changes: 28 additions & 3 deletions webui/src/components/Stores/BladeMemoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
},
Expand All @@ -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);
}
},
Expand All @@ -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);
}
}
Expand Down
31 changes: 28 additions & 3 deletions webui/src/components/Stores/BladeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
},
Expand All @@ -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);
}
},
Expand All @@ -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);
}
},
Expand Down
31 changes: 28 additions & 3 deletions webui/src/components/Stores/HostStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
},
Expand All @@ -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);
}
},
Expand All @@ -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);
}
},
Expand Down

0 comments on commit dad726c

Please sign in to comment.