From 34741ff6365836e814eb18260e4dd04d37f1d4c0 Mon Sep 17 00:00:00 2001 From: "aitor c. urrutia aranburu" Date: Mon, 17 Aug 2026 10:32:49 +0200 Subject: [PATCH] feat: erroreen kudeaketa sartzen du --- src/components/YT2RSS/YT2RSS.tsx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/components/YT2RSS/YT2RSS.tsx b/src/components/YT2RSS/YT2RSS.tsx index c1acc3f..3f9fa35 100644 --- a/src/components/YT2RSS/YT2RSS.tsx +++ b/src/components/YT2RSS/YT2RSS.tsx @@ -5,6 +5,7 @@ import styles from "./YT2RSS.module.scss"; export const YT2RSS: React.FC = () => { const [rssFeed, setRssFeed] = useState(); const [isLoading, setIsLoading] = useState(false); + const [hasError, setHasError] = useState(false); const handleSubmit: SubmitEventHandler = async (e) => { e.preventDefault(); @@ -20,11 +21,20 @@ export const YT2RSS: React.FC = () => { } setIsLoading(true); - const res = await fetch("/api/yt?url=" + encodeURIComponent(ytUrl)); - const data = await res.json(); - setIsLoading(false); - - setRssFeed(data.href); + setHasError(false); + setRssFeed(undefined); + try { + const res = await fetch("/api/yt?url=" + encodeURIComponent(ytUrl)); + if (!res.ok) { + throw new Error("Errorea gertatu da informazioa eskuratzean"); + } + const data = await res.json(); + setRssFeed(data.href); + } catch { + setHasError(true); + } finally { + setIsLoading(false); + } }; return ( @@ -48,6 +58,13 @@ export const YT2RSS: React.FC = () => { {rssFeed &&

{rssFeed}

} + + {hasError && ( +

+ Errore bat izan da. Errebisatu kanalaren URL-a egokia dela eta saiatu + berriro. +

+ )} ); };