mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-28 01:39:29 +08:00
fix: correctly handling 404 errors when getting quotes
This commit is contained in:
parent
d19a95e548
commit
6db321c8fc
1 changed files with 12 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue