fix: correctly handling 404 errors when getting quotes

This commit is contained in:
Miodec 2024-02-23 19:27:12 +01:00
parent d19a95e548
commit 6db321c8fc

View file

@ -48,9 +48,18 @@ class QuotesController {
const normalizedLanguage = removeLanguageSize(language);
if (this.quoteCollection.language !== normalizedLanguage) {
const data = await cachedFetchJson<QuoteData>(
`quotes/${normalizedLanguage}.json`
);
let data: QuoteData;
try {
data = await cachedFetchJson<QuoteData>(
`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;