Skip to content

Commit

Permalink
fix: improve error handling in FlashContext (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrenechea authored Jul 30, 2024
1 parent 3862d8d commit a5bd425
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bmc-ui",
"version": "3.3.1",
"version": "3.3.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
22 changes: 13 additions & 9 deletions src/contexts/FlashContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type AxiosProgressEvent } from "axios";
import { type AxiosError, type AxiosProgressEvent } from "axios";
import { filesize } from "filesize";
import React, {
createContext,
Expand Down Expand Up @@ -125,11 +125,13 @@ export const FlashProvider: React.FC<FlashProviderProps> = ({ children }) => {
},
onError: (error) => {
setIsUploading(false);
const msg = t("firmwareUpgrade.uploadFailed");
setStatusMessage(msg);
const title = t("firmwareUpgrade.uploadFailed");
const errorMessage =
((error as AxiosError).response?.data as string) ?? error.message;
setStatusMessage(`${title}: ${errorMessage}`);
toast({
title: msg,
description: error.message,
title,
description: errorMessage,
variant: "destructive",
});
},
Expand Down Expand Up @@ -159,11 +161,13 @@ export const FlashProvider: React.FC<FlashProviderProps> = ({ children }) => {
},
onError: (error) => {
setIsUploading(false);
const msg = t("flashNode.transferFailed", { nodeId });
setStatusMessage(msg);
const title = t("flashNode.transferFailed", { nodeId });
const errorMessage =
((error as AxiosError).response?.data as string) ?? error.message;
setStatusMessage(`${title}: ${errorMessage}`);
toast({
title: msg,
description: error.message,
title,
description: errorMessage,
variant: "destructive",
});
},
Expand Down

0 comments on commit a5bd425

Please sign in to comment.