From 3b629e8db4890691d6f90329c1c949cc58b3b318 Mon Sep 17 00:00:00 2001 From: phpoh <64546661+phpoh@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:16:01 +0800 Subject: [PATCH] Fix: remove duplicate IPC channel and extract error code sets (#780) --- electron/preload/index.ts | 1 - src/pages/Skills/index.tsx | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/electron/preload/index.ts b/electron/preload/index.ts index 69e33f685..4647ab66a 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -100,7 +100,6 @@ const electronAPI = { 'channel:listConfigured', 'channel:setEnabled', 'channel:validate', - 'channel:validate', 'channel:validateCredentials', // WhatsApp 'channel:requestWhatsAppQr', diff --git a/src/pages/Skills/index.tsx b/src/pages/Skills/index.tsx index e7b903cc0..5c14dbe87 100644 --- a/src/pages/Skills/index.tsx +++ b/src/pages/Skills/index.tsx @@ -36,6 +36,9 @@ import type { Skill } from '@/types/skill'; import { useTranslation } from 'react-i18next'; import type { TFunction } from 'i18next'; +const INSTALL_ERROR_CODES = new Set(['installTimeoutError', 'installRateLimitError']); +const FETCH_ERROR_CODES = new Set(['fetchTimeoutError', 'fetchRateLimitError', 'timeoutError', 'rateLimitError']); +const SEARCH_ERROR_CODES = new Set(['searchTimeoutError', 'searchRateLimitError', 'timeoutError', 'rateLimitError']); @@ -585,7 +588,7 @@ export function Skills() { toast.success(t('toast.installed')); } catch (err) { const errorMessage = err instanceof Error ? err.message : String(err); - if (['installTimeoutError', 'installRateLimitError'].includes(errorMessage)) { + if (INSTALL_ERROR_CODES.has(errorMessage)) { toast.error(t(`toast.${errorMessage}`, { path: skillsDirPath }), { duration: 10000 }); } else { toast.error(t('toast.failedInstall') + ': ' + errorMessage); @@ -739,7 +742,7 @@ export function Skills() {
- {['fetchTimeoutError', 'fetchRateLimitError', 'timeoutError', 'rateLimitError'].includes(error) + {FETCH_ERROR_CODES.has(error) ? t(`toast.${error}`, { path: skillsDirPath }) : error} @@ -851,7 +854,7 @@ export function Skills() {
- {['searchTimeoutError', 'searchRateLimitError', 'timeoutError', 'rateLimitError'].includes(searchError.replace('Error: ', '')) + {SEARCH_ERROR_CODES.has(searchError.replace('Error: ', '')) ? t(`toast.${searchError.replace('Error: ', '')}`, { path: skillsDirPath }) : t('marketplace.searchError')}