From a7f0933e55b1ddbc1db164bf25f74c6cd0ed2971 Mon Sep 17 00:00:00 2001 From: Yi Date: Thu, 9 Jan 2025 11:52:44 +0800 Subject: [PATCH] chore: add checks in the url fetch step of the installFromGitHub --- .../install-from-github/index.tsx | 29 ++++++++++++++----- web/i18n/en-US/plugin.ts | 2 ++ web/i18n/zh-Hans/plugin.ts | 2 ++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/web/app/components/plugins/install-plugin/install-from-github/index.tsx b/web/app/components/plugins/install-plugin/install-from-github/index.tsx index 933934e9ba..7e43907564 100644 --- a/web/app/components/plugins/install-plugin/install-from-github/index.tsx +++ b/web/app/components/plugins/install-plugin/install-from-github/index.tsx @@ -86,13 +86,28 @@ const InstallFromGitHub: React.FC = ({ updatePayload, on }) return } - await fetchReleases(owner, repo).then((fetchedReleases) => { - setState(prevState => ({ - ...prevState, - releases: fetchedReleases, - step: InstallStepFromGitHub.selectPackage, - })) - }) + try { + const fetchedReleases = await fetchReleases(owner, repo) + if (fetchedReleases.length > 0) { + setState(prevState => ({ + ...prevState, + releases: fetchedReleases, + step: InstallStepFromGitHub.selectPackage, + })) + } + else { + Toast.notify({ + type: 'error', + message: t('plugin.error.noReleasesFound'), + }) + } + } + catch (error) { + Toast.notify({ + type: 'error', + message: t('plugin.error.fetchReleasesError'), + }) + } } const handleError = (e: any, isInstall: boolean) => { diff --git a/web/i18n/en-US/plugin.ts b/web/i18n/en-US/plugin.ts index 725450d61d..d5bc3ecbf8 100644 --- a/web/i18n/en-US/plugin.ts +++ b/web/i18n/en-US/plugin.ts @@ -172,6 +172,8 @@ const translation = { }, error: { inValidGitHubUrl: 'Invalid GitHub URL. Please enter a valid URL in the format: https://github.com/owner/repo', + fetchReleasesError: 'Unable to retrieve releases. Please try again later.', + noReleasesFound: 'No releases found. Please check the GitHub repository or the input URL.', }, marketplace: { empower: 'Empower your AI development', diff --git a/web/i18n/zh-Hans/plugin.ts b/web/i18n/zh-Hans/plugin.ts index fc1a052e39..50219dc322 100644 --- a/web/i18n/zh-Hans/plugin.ts +++ b/web/i18n/zh-Hans/plugin.ts @@ -172,6 +172,8 @@ const translation = { }, error: { inValidGitHubUrl: '无效的 GitHub URL。请输入格式为 https://github.com/owner/repo 的有效 URL', + fetchReleasesError: '无法获取发布版本。请稍后再试。', + noReleasesFound: '未找到发布版本。请检查 GitHub 仓库或输入的 URL。', }, marketplace: { empower: '助力您的 AI 开发',