fix(error-handling): isolate tray menu update failures from main operations
Previously, if updateTrayMenu() failed after a successful main operation (like sorting, adding, or updating providers), the entire operation would appear to fail with a misleading error message, even though the core functionality had already succeeded. This resulted in false negative feedback where: - Backend data was successfully updated - Frontend UI was successfully refreshed - Tray menu failed to update - User saw "operation failed" message (incorrect) Changes: - Wrap updateTrayMenu() calls in nested try-catch blocks - Log tray menu failures separately with descriptive messages - Ensure main operation success is reported accurately - Prevent tray menu failures from triggering main operation error handlers Files modified: - src/hooks/useDragSort.ts (drag-and-drop sorting) - src/lib/query/mutations.ts (add/delete/switch mutations) - src/hooks/useProviderActions.ts (update provider) This fixes the bug introduced in PR #179 and prevents similar issues across all provider operations.
This commit is contained in:
@@ -74,8 +74,15 @@ export function useDragSort(providers: Record<string, Provider>, appId: AppId) {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: ["providers", appId],
|
||||
});
|
||||
// 更新托盘菜单以反映新的排序
|
||||
await providersApi.updateTrayMenu();
|
||||
|
||||
// 更新托盘菜单以反映新的排序(失败不影响主操作)
|
||||
try {
|
||||
await providersApi.updateTrayMenu();
|
||||
} catch (trayError) {
|
||||
console.error("Failed to update tray menu after sort", trayError);
|
||||
// 托盘菜单更新失败不影响排序成功
|
||||
}
|
||||
|
||||
toast.success(
|
||||
t("provider.sortUpdated", {
|
||||
defaultValue: "排序已更新",
|
||||
|
||||
Reference in New Issue
Block a user