Skip to content

Commit

Permalink
fix: correctly handling 404 errors when getting quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Miodec committed Feb 23, 2024
1 parent d19a95e commit 6db321c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frontend/src/ts/controllers/quotes-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6db321c

Please sign in to comment.