Skip to content

Commit

Permalink
Add explicit error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
qstokkink committed Sep 17, 2024
1 parent 0efabcd commit 029c98f
Show file tree
Hide file tree
Showing 46 changed files with 1,135 additions and 297 deletions.
27 changes: 26 additions & 1 deletion src/tribler/ui/public/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,30 @@
"ErrorNotification": "Tribler encountered an error! What do you want to do?",
"ErrorSearchButton": "Search for solutions",
"ErrorReportButton": "Report on GitHub",
"ErrorIgnoreButton": "Ignore"
"ErrorIgnoreButton": "Ignore",
"ToastErrorGenNetworkErr": "Connection error.",
"ToastErrorSetLanguage": "Failed set language!",
"ToastErrorShutdown": "Failed to send shutdown signal!",
"ToastErrorDefaultDLDir": "Failed to retrieve default download directory!",
"ToastErrorDirectoryAdd": "Failed to add directory!",
"ToastErrorCreateTorrent": "Failed to create torrent {{name}}!",
"ToastErrorGetSettings": "Failed retrieve settings!",
"ToastErrorSetSettings": "Failed save settings!",
"ToastErrorGetMetainfo": "Failed to retrieve metadata!",
"ToastErrorBrowseFiles": "Failed to open path!",
"ToastErrorEnableHealth": "Failed enable health measurements!",
"ToastErrorDisableHealth": "Failed disable health measurements!",
"ToastErrorEnableAsyncio": "Failed enable asyncio debugger!",
"ToastErrorDisableAsyncio": "Failed disable asyncio debugger!",
"ToastErrorSlowness": "Failed change slowness threshold!",
"ToastErrorDownloadStart": "Failed to start download!",
"ToastErrorDownloadPlay": "Failed to play download!",
"ToastErrorDownloadStop": "Failed to stop download!",
"ToastErrorDownloadRemove": "Failed to remove download!",
"ToastErrorDownloadCheck": "Failed to check download!",
"ToastErrorDownloadMove": "Failed to move download!",
"ToastErrorDownloadSetHops": "Failed change the anonymity of download!",
"ToastErrorDownloadSetFiles": "Failed to set files for download!",
"ToastErrorUpgradeFailed": "Upgrade failed!",
"ToastErrorRemoveVersion": "Failed to remove version {{version}}!"
}
27 changes: 26 additions & 1 deletion src/tribler/ui/public/locales/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,30 @@
"ErrorNotification": "¡Tribler encontró un error! ",
"ErrorSearchButton": "Buscar soluciones",
"ErrorReportButton": "Informe en GitHub",
"ErrorIgnoreButton": "Ignorar"
"ErrorIgnoreButton": "Ignorar",
"ToastErrorGenNetworkErr": "Error de conexión.",
"ToastErrorSetLanguage": "¡Error al establecer el idioma!",
"ToastErrorShutdown": "¡No se pudo enviar la señal de apagado!",
"ToastErrorDefaultDLDir": "¡No se pudo recuperar el directorio de descarga predeterminado!",
"ToastErrorDirectoryAdd": "¡No se pudo agregar el directorio!",
"ToastErrorCreateTorrent": "No se pudo crear torrent {{name}}!",
"ToastErrorGetSettings": "¡Error al recuperar la configuración!",
"ToastErrorSetSettings": "¡Error al guardar la configuración!",
"ToastErrorGetMetainfo": "¡No se pudieron recuperar los metadatos!",
"ToastErrorBrowseFiles": "¡No se pudo abrir el camino!",
"ToastErrorEnableHealth": "¡Error al habilitar las mediciones de salud!",
"ToastErrorDisableHealth": "¡Error al desactivar las mediciones de salud!",
"ToastErrorEnableAsyncio": "¡Error al habilitar el depurador asyncio!",
"ToastErrorDisableAsyncio": "¡Error al desactivar el depurador asyncio!",
"ToastErrorSlowness": "¡Umbral de lentitud de cambio fallido!",
"ToastErrorDownloadStart": "¡No se pudo iniciar la descarga!",
"ToastErrorDownloadPlay": "¡No se pudo reproducir la descarga!",
"ToastErrorDownloadStop": "¡No se pudo detener la descarga!",
"ToastErrorDownloadRemove": "¡No se pudo eliminar la descarga!",
"ToastErrorDownloadCheck": "¡No se pudo verificar la descarga!",
"ToastErrorDownloadMove": "¡No se pudo mover la descarga!",
"ToastErrorDownloadSetHops": "¡Error al cambiar el anonimato de la descarga!",
"ToastErrorDownloadSetFiles": "¡No se pudieron configurar los archivos para descargar!",
"ToastErrorUpgradeFailed": "¡La actualización falló!",
"ToastErrorRemoveVersion": "No se pudo eliminar la versión {{version}}!"
}
27 changes: 26 additions & 1 deletion src/tribler/ui/public/locales/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,30 @@
"ErrorNotification": "Tribler encontrou um erro! ",
"ErrorSearchButton": "Procure soluções",
"ErrorReportButton": "Relatório no GitHub",
"ErrorIgnoreButton": "Ignorar"
"ErrorIgnoreButton": "Ignorar",
"ToastErrorGenNetworkErr": "Erro de conexão.",
"ToastErrorSetLanguage": "Falha ao definir idioma!",
"ToastErrorShutdown": "Falha ao enviar sinal de desligamento!",
"ToastErrorDefaultDLDir": "Falha ao recuperar o diretório de download padrão!",
"ToastErrorDirectoryAdd": "Falha ao adicionar diretório!",
"ToastErrorCreateTorrent": "Falha ao criar torrent {{name}}!",
"ToastErrorGetSettings": "Falha ao recuperar configurações!",
"ToastErrorSetSettings": "Falha ao salvar configurações!",
"ToastErrorGetMetainfo": "Falha ao recuperar metadados!",
"ToastErrorBrowseFiles": "Falha ao abrir caminho!",
"ToastErrorEnableHealth": "Falha ao ativar medições de integridade!",
"ToastErrorDisableHealth": "Falha ao desativar medições de integridade!",
"ToastErrorEnableAsyncio": "Falha ao ativar o depurador assíncrono!",
"ToastErrorDisableAsyncio": "Falha ao desativar o depurador assíncrono!",
"ToastErrorSlowness": "Falha ao alterar limite de lentidão!",
"ToastErrorDownloadStart": "Falha ao iniciar o download!",
"ToastErrorDownloadPlay": "Falha ao reproduzir o download!",
"ToastErrorDownloadStop": "Falha ao interromper o download!",
"ToastErrorDownloadRemove": "Falha ao remover o download!",
"ToastErrorDownloadCheck": "Falha ao verificar o download!",
"ToastErrorDownloadMove": "Falha ao mover o download!",
"ToastErrorDownloadSetHops": "Falha ao alterar o anonimato do download!",
"ToastErrorDownloadSetFiles": "Falha ao definir arquivos para download!",
"ToastErrorUpgradeFailed": "Falha na atualização!",
"ToastErrorRemoveVersion": "Falha ao remover a versão {{version}}!"
}
27 changes: 26 additions & 1 deletion src/tribler/ui/public/locales/ru_RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,30 @@
"ErrorNotification": "Триблер обнаружил ошибку! ",
"ErrorSearchButton": "Поиск решений",
"ErrorReportButton": "Отчет на GitHub",
"ErrorIgnoreButton": "игнорировать"
"ErrorIgnoreButton": "игнорировать",
"ToastErrorGenNetworkErr": "Ошибка подключения.",
"ToastErrorSetLanguage": "Не удалось установить язык!",
"ToastErrorShutdown": "Не удалось отправить сигнал выключения!",
"ToastErrorDefaultDLDir": "Не удалось получить каталог загрузки по умолчанию!",
"ToastErrorDirectoryAdd": "Не удалось добавить каталог!",
"ToastErrorCreateTorrent": "Не удалось создать торрент {{name}}!",
"ToastErrorGetSettings": "Не удалось получить настройки!",
"ToastErrorSetSettings": "Не удалось сохранить настройки!",
"ToastErrorGetMetainfo": "Не удалось получить метаданные!",
"ToastErrorBrowseFiles": "Не удалось открыть путь!",
"ToastErrorEnableHealth": "Не удалось включить измерения состояния здоровья!",
"ToastErrorDisableHealth": "Не удалось отключить измерения здоровья!",
"ToastErrorEnableAsyncio": "Не удалось включить асинхронный отладчик!",
"ToastErrorDisableAsyncio": "Не удалось отключить асинхронный отладчик!",
"ToastErrorSlowness": "Не удалось изменить порог медленности!",
"ToastErrorDownloadStart": "Не удалось начать загрузку!",
"ToastErrorDownloadPlay": "Не удалось загрузить игру!",
"ToastErrorDownloadStop": "Не удалось остановить загрузку!",
"ToastErrorDownloadRemove": "Не удалось удалить загрузку!",
"ToastErrorDownloadCheck": "Не удалось проверить загрузку!",
"ToastErrorDownloadMove": "Не удалось переместить загрузку!",
"ToastErrorDownloadSetHops": "Не удалось изменить анонимность загрузки!",
"ToastErrorDownloadSetFiles": "Не удалось установить файлы для скачивания!",
"ToastErrorUpgradeFailed": "Обновление не удалось!",
"ToastErrorRemoveVersion": "Не удалось удалить версию {{version}}!"
}
27 changes: 26 additions & 1 deletion src/tribler/ui/public/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,30 @@
"ErrorNotification": "Tribler 遇到错误!",
"ErrorSearchButton": "搜索解决方案",
"ErrorReportButton": "在 GitHub 上报告",
"ErrorIgnoreButton": "忽略"
"ErrorIgnoreButton": "忽略",
"ToastErrorGenNetworkErr": "连接错误。",
"ToastErrorSetLanguage": "设置语言失败!",
"ToastErrorShutdown": "发送关机信号失败!",
"ToastErrorDefaultDLDir": "检索默认下载目录失败!",
"ToastErrorDirectoryAdd": "添加目录失败!",
"ToastErrorCreateTorrent": "创建 torrent 失败 {{name}}!",
"ToastErrorGetSettings": "检索设置失败!",
"ToastErrorSetSettings": "保存设置失败!",
"ToastErrorGetMetainfo": "检索元数据失败!",
"ToastErrorBrowseFiles": "打开路径失败!",
"ToastErrorEnableHealth": "启用健康测量失败!",
"ToastErrorDisableHealth": "禁用运行状况测量失败!",
"ToastErrorEnableAsyncio": "启用异步调试器失败!",
"ToastErrorDisableAsyncio": "禁用异步调试器失败!",
"ToastErrorSlowness": "更改缓慢阈值失败!",
"ToastErrorDownloadStart": "无法开始下载!",
"ToastErrorDownloadPlay": "下载播放失败!",
"ToastErrorDownloadStop": "无法停止下载!",
"ToastErrorDownloadRemove": "删除下载失败!",
"ToastErrorDownloadCheck": "检查下载失败!",
"ToastErrorDownloadMove": "移动下载失败!",
"ToastErrorDownloadSetHops": "更改下载匿名失败!",
"ToastErrorDownloadSetFiles": "设置文件下载失败!",
"ToastErrorUpgradeFailed": "升级失败!",
"ToastErrorRemoveVersion": "删除版本失败 {{version}}!"
}
11 changes: 10 additions & 1 deletion src/tribler/ui/src/components/add-torrent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import toast from 'react-hot-toast';
import { Button } from "./ui/button";
import { PlusIcon, Cloud, File as FileIcon } from "lucide-react";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "./ui/dropdown-menu";
import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "./ui/dialog";
import { triblerService } from "@/services/tribler.service";
import { isErrorDict } from "@/services/reporting";
import { Input } from "./ui/input";
import SaveAs from "@/dialogs/SaveAs";
import CreateTorrent from "@/dialogs/CreateTorrent";
Expand Down Expand Up @@ -130,7 +132,14 @@ export function AddTorrent() {
}
else {
for (let file of files) {
(async () => { await triblerService.startDownloadFromFile(file) })();
(async () => {
const response = await triblerService.startDownloadFromFile(file);
if (response === undefined) {
toast.error(`${t("ToastErrorStartDownload")} ${t("ToastErrorGenNetworkErr")}`);
} else if (isErrorDict(response)){
toast.error(`${t("ToastErrorStartDownload")} ${response.error}`);
}
})();
}
}
navigate("/downloads/all");
Expand Down
11 changes: 8 additions & 3 deletions src/tribler/ui/src/components/language-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Button } from "./ui/button";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu";
import { useTranslation } from "react-i18next";
import { triblerService } from "@/services/tribler.service";
import { isErrorDict } from "@/services/reporting";
import { useEffect } from "react";
import toast from 'react-hot-toast';


const LanguageSelect = () => {
Expand All @@ -19,9 +21,12 @@ const LanguageSelect = () => {
const changeLanguage = async (lng: string) => {
setLanguage(lng);
i18n.changeLanguage(lng);
await triblerService.setSettings({
ui: { lang: lng }
});
const response = await triblerService.setSettings({ ui: { lang: lng } });
if (response === undefined) {
toast.error(`${t("ToastErrorSetLanguage")} ${t("ToastErrorGenNetworkErr")}`);
} else if (isErrorDict(response)){
toast.error(`${t("ToastErrorSetLanguage")} ${response.error}`);
}
};

return (
Expand Down
11 changes: 10 additions & 1 deletion src/tribler/ui/src/components/layouts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ModeToggle } from "../mode-toggle";
import { Search } from "./Search";
import LanguageSelect from "../language-select";
import { triblerService } from "@/services/tribler.service";
import { isErrorDict } from "@/services/reporting";
import { useInterval } from "@/hooks/useInterval";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../ui/dialog";
import { useEffect, useRef, useState } from "react";
Expand Down Expand Up @@ -133,7 +134,15 @@ export function Header() {
<Button
variant="ghost"
className="w-9 px-0"
onClick={() => triblerService.shutdown()}
onClick={() => {
triblerService.shutdown().then((response) => {
if (response === undefined) {
toast.error(`${"ToastErrorShutdown"} ${"ToastErrorGenNetworkErr"}`);
} else if (isErrorDict(response)){
toast.error(`${"ToastErrorShutdown"} ${response.error}`);
}
})
}}
>
<ExitIcon />
</Button>
Expand Down
8 changes: 7 additions & 1 deletion src/tribler/ui/src/components/layouts/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import { triblerService } from '@/services/tribler.service';
import { isErrorDict } from "@/services/reporting";
import { Autocomplete } from '../ui/autocomplete';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
Expand All @@ -12,7 +13,12 @@ export function Search() {
<Autocomplete
placeholder={t('SearchPlaceholder')}
completions={async (value) => {
return await triblerService.getCompletions(value);
const response = await triblerService.getCompletions(value);
if (response === undefined || isErrorDict(response)) {
return [];
} else {
return response;
}
}}
onChange={(query) => navigate('/search?query=' + query)}
/>
Expand Down
14 changes: 13 additions & 1 deletion src/tribler/ui/src/components/swarm-health.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import toast from 'react-hot-toast';
import { Torrent } from "@/models/torrent.model";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip";
import { formatTimeAgo } from "@/lib/utils";
import { triblerService } from "@/services/tribler.service";
import { isErrorDict } from "@/services/reporting";


export function SwarmHealth({ torrent }: { torrent: Torrent }) {
const { t } = useTranslation();
const [checking, setChecking] = useState<boolean>(false)

useEffect(() => {
Expand All @@ -26,8 +30,16 @@ export function SwarmHealth({ torrent }: { torrent: Torrent }) {
<div
className="flex flex-nowrap items-center whitespace-nowrap cursor-button"
onClick={() => {
triblerService.getTorrentHealth(torrent.infohash)
setChecking(true);
triblerService.getTorrentHealth(torrent.infohash).then((response) => {
if (response === undefined){
setChecking(false);
toast.error(`${t("ToastErrorDownloadCheck")} ${t("ToastErrorGenNetworkErr")}`);
} else if (isErrorDict(response)) {
setChecking(false);
toast.error(`${t("ToastErrorDownloadCheck")} ${response.error}`);
}
});
}}
>
{checking ?
Expand Down
Loading

0 comments on commit 029c98f

Please sign in to comment.