From c54557c11ca83fac848045810b50de70ea09f2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 4 Jul 2026 22:25:12 +0800 Subject: [PATCH] Drop unused error parameter from apiError Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01RaRBJFZKSTA7naHGuQHfnQ --- src/module/apiError.js | 3 +-- src/stores/acctMgmt.ts | 16 ++++++++-------- src/stores/allMapData.ts | 20 ++++++++++---------- src/stores/compare.ts | 6 +++--- src/stores/conformance.ts | 14 +++++--------- src/stores/files.ts | 18 +++++++++--------- src/stores/login.ts | 2 +- src/stores/performance.ts | 2 +- tests/unit/module/apiError.test.js | 23 +++++++++++++++++++++++ 9 files changed, 61 insertions(+), 43 deletions(-) create mode 100644 tests/unit/module/apiError.test.js diff --git a/src/module/apiError.js b/src/module/apiError.js index 438b68f..6d83ff3 100644 --- a/src/module/apiError.js +++ b/src/module/apiError.js @@ -14,10 +14,9 @@ import "vue-toast-notification/dist/theme-sugar.css"; * 401 errors are handled by the axios response interceptor * in api/client.js. * - * @param {Object} error - The error object from the API call. * @param {string} toastMessage - The message to display in the toast. */ -export default function apiError(error, toastMessage) { +export default function apiError(toastMessage) { const $toast = useToast(); $toast.default(toastMessage, { position: "bottom" }); } diff --git a/src/stores/acctMgmt.ts b/src/stores/acctMgmt.ts index f49c37a..f192a25 100644 --- a/src/stores/acctMgmt.ts +++ b/src/stores/acctMgmt.ts @@ -103,7 +103,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { const customizedResponseData = await this.customizeAllUserList(response.data); this.allUserAccountList = await this.moveCurrentLoginUserToFirstRow(customizedResponseData); } catch (error) { - apiError(error, 'Failed to get all users.'); + apiError('Failed to get all users.'); } }, /** @@ -155,7 +155,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { setTimeout(() => this.resetJustCreateFlag(), JUST_CREATE_ACCOUNT_HOT_DURATION_MINS * 1000 * 60); } } catch (error) { - apiError(error, 'Failed to add a new account.'); + apiError('Failed to add a new account.'); } }, /** @@ -170,7 +170,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { const response = await apiClient.delete(apiDelete); return response.status === 200; } catch (error) { - apiError(error, 'Failed to delete the account.'); + apiError('Failed to delete the account.'); return false; } }, @@ -191,7 +191,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { }); return response.status === 200; } catch (error) { - apiError(error, 'Failed to edit the account.'); + apiError('Failed to edit the account.'); return false; } }, @@ -207,7 +207,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { }); return response.status === 200; } catch (error) { - apiError(error, 'Failed to edit name of account.'); + apiError('Failed to edit name of account.'); return false; } }, @@ -224,7 +224,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { }); return response.status === 200; } catch (error) { - apiError(error, 'Failed to edit password of account.'); + apiError('Failed to edit password of account.'); return false; } }, @@ -239,7 +239,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { const response = await apiClient.put(apiAddRole); return response.status === 200; } catch (error) { - apiError(error, 'Failed to add role to the account.'); + apiError('Failed to add role to the account.'); return false; } }, @@ -254,7 +254,7 @@ export const useAcctMgmtStore = defineStore('acctMgmtStore', { const response = await apiClient.delete(apiDeleteRole); return response.status === 200; } catch (error) { - apiError(error, 'Failed to delete a role from the account.'); + apiError('Failed to delete a role from the account.'); return false; } }, diff --git a/src/stores/allMapData.ts b/src/stores/allMapData.ts index 8f0ad2b..5b78a7a 100644 --- a/src/stores/allMapData.ts +++ b/src/stores/allMapData.ts @@ -172,7 +172,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.allStats = response.data.stats; this.allInsights = response.data.insights; } catch (error) { - apiError(error, "Failed to load the Map."); + apiError("Failed to load the Map."); } }, /** @@ -191,7 +191,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.allBaseTrace = baseResponse.data; } } catch (error) { - apiError(error, "Failed to load the Trace."); + apiError("Failed to load the Trace."); } }, /** @@ -233,7 +233,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.infinite404 = 404; return; } - apiError(error, "Failed to load the Trace Detail."); + apiError("Failed to load the Trace Detail."); return []; } }, @@ -278,7 +278,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.infinite404 = 404; return; } - apiError(error, "Failed to load the Base Trace Detail."); + apiError("Failed to load the Base Trace Detail."); return []; } }, @@ -309,7 +309,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.allFilterTimeframe.x_axis.max = max === null ? null : moment(max).format("YYYY/MM/DD HH:mm"); } catch (error) { - apiError(error, "Failed to load the Filter Parameters."); + apiError("Failed to load the Filter Parameters."); } }, /** @@ -323,7 +323,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { const response = await apiClient.post(api, this.postRuleData); this.hasResultRule = response.data.result; } catch (error) { - apiError(error, "Failed to load the Has Result."); + apiError("Failed to load the Has Result."); } }, /** @@ -337,7 +337,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { const response = await apiClient.post(api, this.postRuleData); this.tempFilterId = response.data.id; } catch (error) { - apiError(error, "Failed to add the Temporary Filters."); + apiError("Failed to add the Temporary Filters."); } }, /** @@ -357,7 +357,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.createFilterId = response.data.id; this.tempFilterId = null; } catch (error) { - apiError(error, "Failed to load the Filters."); + apiError("Failed to load the Filters."); } }, /** @@ -375,7 +375,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.filterName = response.data.name; this.baseLogId = response.data.log?.id; } catch (error) { - apiError(error, "Failed to get Filter Detail."); + apiError("Failed to get Filter Detail."); } } }, @@ -392,7 +392,7 @@ export const useAllMapDataStore = defineStore("allMapDataStore", { this.isUpdateFilter = response.status === 200; this.tempFilterId = null; } catch (error) { - apiError(error, "Failed to update an Existing Filter."); + apiError("Failed to update an Existing Filter."); } }, }, diff --git a/src/stores/compare.ts b/src/stores/compare.ts index c19f339..25fbd17 100644 --- a/src/stores/compare.ts +++ b/src/stores/compare.ts @@ -37,7 +37,7 @@ export const useCompareStore = defineStore("compareStore", { const response = await apiClient.get(api); this.allCompareDashboardData = response.data; } catch (error) { - apiError(error, "Failed to load the Compare."); + apiError("Failed to load the Compare."); } }, /** @@ -63,7 +63,7 @@ export const useCompareStore = defineStore("compareStore", { return response.data.stats; } catch (error) { - apiError(error, "Failed to load the Compare's States."); + apiError("Failed to load the Compare's States."); return null; } }, @@ -79,7 +79,7 @@ export const useCompareStore = defineStore("compareStore", { if (file) return file.name; } catch (error) { - apiError(error, "Failed to load the Compare's file name."); + apiError("Failed to load the Compare's file name."); } return ""; }, diff --git a/src/stores/conformance.ts b/src/stores/conformance.ts index 9cadb2a..6a18ab3 100644 --- a/src/stores/conformance.ts +++ b/src/stores/conformance.ts @@ -276,7 +276,7 @@ export const useConformanceStore = defineStore("conformanceStore", { this.allWaitingTime = response.data.waiting_time; this.allCycleTime = response.data.cycle_time; } catch (error) { - apiError(error, "Failed to load the Conformance Parameters."); + apiError("Failed to load the Conformance Parameters."); } }, /** @@ -295,7 +295,7 @@ export const useConformanceStore = defineStore("conformanceStore", { this.conformanceLogTempCheckId = response.data.id; } } catch (error) { - apiError(error, "Failed to add the Temporary Check for a file."); + apiError("Failed to add the Temporary Check for a file."); } }, /** @@ -312,7 +312,7 @@ export const useConformanceStore = defineStore("conformanceStore", { this.allConformanceTempReportData = response.data; } } catch (error) { - apiError(error, "Failed to Get the Temporary Log Conformance Report."); + apiError("Failed to Get the Temporary Log Conformance Report."); } }, /** @@ -326,7 +326,6 @@ export const useConformanceStore = defineStore("conformanceStore", { this.allIssueTraces = response.data.traces; } catch (error) { apiError( - error, "Failed to Get the detail of a temporary log conformance issue.", ); } @@ -350,7 +349,6 @@ export const useConformanceStore = defineStore("conformanceStore", { return null; } apiError( - error, "Failed to Get the detail of a temporary log conformance issue.", ); return null; @@ -367,7 +365,6 @@ export const useConformanceStore = defineStore("conformanceStore", { this.allLoopTraces = response.data.traces; } catch (error) { apiError( - error, "Failed to Get the detail of a temporary log conformance loop.", ); } @@ -391,7 +388,6 @@ export const useConformanceStore = defineStore("conformanceStore", { return null; } apiError( - error, "Failed to Get the detail of a temporary log conformance loop.", ); return null; @@ -419,7 +415,7 @@ export const useConformanceStore = defineStore("conformanceStore", { this.conformanceLogTempCheckId = null; } } catch (error) { - apiError(error, "Failed to add the Conformance Check for a file."); + apiError("Failed to add the Conformance Check for a file."); } }, /** @@ -435,7 +431,7 @@ export const useConformanceStore = defineStore("conformanceStore", { this.conformanceLogTempCheckId = null; this.conformanceFilterTempCheckId = null; } catch (error) { - apiError(error, "Failed to update an Existing Conformance."); + apiError("Failed to update an Existing Conformance."); } }, /** diff --git a/src/stores/files.ts b/src/stores/files.ts index c42acd0..9b41341 100644 --- a/src/stores/files.ts +++ b/src/stores/files.ts @@ -146,7 +146,7 @@ export const useFilesStore = defineStore("filesStore", { : null; }); } catch (error) { - apiError(error, "Failed to load the files."); + apiError("Failed to load the files."); } }, /** @@ -180,7 +180,7 @@ export const useFilesStore = defineStore("filesStore", { } } else { Swal.close(); // Close the loading progress bar - apiError(error, "Failed to upload the files."); + apiError("Failed to upload the files."); } } }, @@ -195,7 +195,7 @@ export const useFilesStore = defineStore("filesStore", { const response = await apiClient.get(api); this.allUploadDetail = response.data.preview; } catch (error) { - apiError(error, "Failed to get upload detail."); + apiError("Failed to get upload detail."); } }, /** @@ -223,7 +223,7 @@ export const useFilesStore = defineStore("filesStore", { uploadFailedSecond(detail); } else { Swal.close(); // Close the loading progress bar - apiError(error, "Failed to upload the log files."); + apiError("Failed to upload the log files."); } } }, @@ -247,7 +247,7 @@ export const useFilesStore = defineStore("filesStore", { this.uploadFileName = null; await this.fetchAllFiles(); } catch (error) { - apiError(error, "Failed to rename."); + apiError("Failed to rename."); } }, /** @@ -262,7 +262,7 @@ export const useFilesStore = defineStore("filesStore", { ); this.allDependentsData = response.data; } catch (error) { - apiError(error, "Failed to get Dependents of the files."); + apiError("Failed to get Dependents of the files."); } }, /** @@ -282,7 +282,7 @@ export const useFilesStore = defineStore("filesStore", { await this.fetchAllFiles(); await deleteSuccess(); } catch (error) { - apiError(error, "Failed to delete."); + apiError("Failed to delete."); } finally { loading.isLoading = false; } @@ -300,7 +300,7 @@ export const useFilesStore = defineStore("filesStore", { try { await apiClient.delete(api); } catch (error) { - apiError(error, "Failed to Remove a Deletion Record."); + apiError("Failed to Remove a Deletion Record."); } finally { loading.isLoading = false; } @@ -325,7 +325,7 @@ export const useFilesStore = defineStore("filesStore", { link.click(); globalThis.URL.revokeObjectURL(url); } catch (error) { - apiError(error, "Failed to download."); + apiError("Failed to download."); } }, }, diff --git a/src/stores/login.ts b/src/stores/login.ts index ab58b57..cca11df 100644 --- a/src/stores/login.ts +++ b/src/stores/login.ts @@ -121,7 +121,7 @@ export const useLoginStore = defineStore("loginStore", { this.userData = response.data; } catch (error) { - apiError(error, "Failed to load user data."); + apiError("Failed to load user data."); } }, /** diff --git a/src/stores/performance.ts b/src/stores/performance.ts index f7cc8af..6f316e6 100644 --- a/src/stores/performance.ts +++ b/src/stores/performance.ts @@ -52,7 +52,7 @@ export const usePerformanceStore = defineStore("performanceStore", { const response = await apiClient.get(api); this.allPerformanceData = response.data; } catch (error) { - apiError(error, "Failed to load the Performance."); + apiError("Failed to load the Performance."); } }, /** diff --git a/tests/unit/module/apiError.test.js b/tests/unit/module/apiError.test.js new file mode 100644 index 0000000..15300a7 --- /dev/null +++ b/tests/unit/module/apiError.test.js @@ -0,0 +1,23 @@ +// The Lucia project. +// Copyright 2026-2026 DSP, inc. All rights reserved. +// Authors: +// imacat.yang@dsp.im (imacat), 2026/07/04 +// AI assistance: Claude Code (Anthropic) + +import { describe, it, expect, vi } from "vitest"; +import apiError from "@/module/apiError.js"; + +const toastDefault = vi.fn(); + +vi.mock("vue-toast-notification", () => ({ + useToast: () => ({ default: toastDefault }), +})); + +describe("apiError", () => { + it("shows the message as a toast at the bottom", () => { + apiError("some message"); + expect(toastDefault).toHaveBeenCalledWith("some message", { + position: "bottom", + }); + }); +});