From 7b176b0d82bd4136a9aea907c90fbae51a5ef4a1 Mon Sep 17 00:00:00 2001 From: yossydev Date: Sun, 17 Nov 2024 15:49:41 +0900 Subject: [PATCH] chore: error handling --- app/islands/TranslatorButton.tsx | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/islands/TranslatorButton.tsx b/app/islands/TranslatorButton.tsx index 0afca2b..888c8e7 100644 --- a/app/islands/TranslatorButton.tsx +++ b/app/islands/TranslatorButton.tsx @@ -40,13 +40,17 @@ const TranslatorButton: FC = ({ content }) => { // biome-ignore lint: lint/suspicious/noExplicitAny "createTranslator" in (self.translation as any) ) { - // biome-ignore lint: lint/suspicious/noExplicitAny - const translator = await (self.translation as any).createTranslator({ - sourceLanguage: "ja", - targetLanguage: e.target.value, - }); - const res = await translator.translate(content); - console.log("res", res); + try { + // biome-ignore lint: lint/suspicious/noExplicitAny + const translator = await (self.translation as any).createTranslator({ + sourceLanguage: "ja", + targetLanguage: e.target.value, + }); + const res = await translator.translate(content); + console.log("res", res); + } catch (error) { + console.error("translator error", error); + } } else { window.alert("The Translator API is not supported"); }