From 6db321c8fc16aff9ac2919da787fca3d511a6f20 Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 23 Feb 2024 19:27:12 +0100 Subject: [PATCH] fix: correctly handling 404 errors when getting quotes --- frontend/src/ts/controllers/quotes-controller.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/ts/controllers/quotes-controller.ts b/frontend/src/ts/controllers/quotes-controller.ts index 4535c521bbdb..3f3778727761 100644 --- a/frontend/src/ts/controllers/quotes-controller.ts +++ b/frontend/src/ts/controllers/quotes-controller.ts @@ -48,9 +48,18 @@ class QuotesController { const normalizedLanguage = removeLanguageSize(language); if (this.quoteCollection.language !== normalizedLanguage) { - const data = await cachedFetchJson( - `quotes/${normalizedLanguage}.json` - ); + let data: QuoteData; + try { + data = await cachedFetchJson( + `quotes/${normalizedLanguage}.json` + ); + } catch (e) { + if (e instanceof Error && e?.message?.includes("404")) { + return defaultQuoteCollection; + } else { + throw e; + } + } if (data.quotes === undefined || data.quotes.length === 0) { return defaultQuoteCollection;