Skip to content

Commit

Permalink
Fallback to packaged data files if fetch fails
Browse files Browse the repository at this point in the history
Resolves #21
  • Loading branch information
Nixinova committed Jun 28, 2023
1 parent 8ce5a87 commit 6909c64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Next
- Fixed cached data files having formatting issues.
- Changed fetching of data files to fallback to using the packaged files if the fetch request fails.
- Fixed packaged data files having formatting issues.

## 2.5.5
*2023-06-25*
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/load-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ async function loadWebFile(file: string): Promise<string> {
if (cachedContent) return cachedContent;
// Otherwise cache the request
const dataUrl = (file: string): string => `https://raw.githubusercontent.com/github/linguist/HEAD/lib/linguist/${file}`;
const fileContent = await fetch(dataUrl(file)).then(data => data.text());
// Load file content, falling back to the local file if the request fails
const fileContent = await fetch(dataUrl(file)).then(data => data.text()).catch(async () => await loadLocalFile(file));
cache.set(file, fileContent);
return fileContent;
}
Expand Down

0 comments on commit 6909c64

Please sign in to comment.