fix(ui): enforce strict type safety in bulk action error handling
Addresses PR feedback: - Replaces forbidden any type in catch block with unknown - Adds type discrimination using axios.isAxiosError and instanceof Error - Narrows error type for logger.error compatibility Fixes #3602
This commit is contained in:
1 parent
387cb35494
commit
baf7344e2d
1 file changed
+13
-3
@@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import axios from "axios";
|
||||||
import { post } from "@/Utils/ApiClient";
|
import { post } from "@/Utils/ApiClient";
|
||||||
import { useToast } from "@/Hooks/UseToast";
|
import { useToast } from "@/Hooks/UseToast";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
@@ -55,9 +56,18 @@ export const useBulkMonitorActions = (
|
|||||||
|
|
||||||
setSelectedRows([]);
|
setSelectedRows([]);
|
||||||
refetch();
|
refetch();
|
||||||
} catch (err: any) {
|
} catch (err: unknown) {
|
||||||
const errMsg = err?.response?.data?.msg || err.message || "An error occurred";
|
let errMsg = "An error occurred";
|
||||||
logger.error("Bulk pause/resume failed", err, { pause });
|
|
||||||
|
if (axios.isAxiosError(err)) {
|
||||||
|
errMsg = err.response?.data?.msg || err.message || errMsg;
|
||||||
|
} else if (err instanceof Error) {
|
||||||
|
errMsg = err.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error("Bulk pause/resume failed", err instanceof Error ? err : undefined, {
|
||||||
|
pause,
|
||||||
|
});
|
||||||
toastError(errMsg);
|
toastError(errMsg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user