Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added alternative query of gist content from raw URL if initial fetch… #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/fileSystem/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,28 @@ const isBinaryPath = require("is-binary-path");
export async function getFileContents(file: GistFile) {
if (file.truncated || !file.content) {
const responseType = isBinaryPath(file.filename!) ? "arraybuffer" : "text";
const { data } = await axios.get(file.raw_url!, {
responseType,
transformResponse: (data) => {
return data;
try {
const { data } = await axios.get(file.raw_url!, {
responseType,
transformResponse: (data) => {
return data;
}
});
file.content = data;
} catch (error: any) {
console.error(`Error fetching file content: ${(error as Error).message}`);
// Fallback: try to fetch content directly from raw_url
try {
const response = await fetch(file.raw_url!);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
file.content = await response.text();
} catch (fallbackError: any) {
console.error(`Fallback fetch failed: ${(fallbackError as Error).message}`);
throw new Error(`Failed to fetch file content: ${fallbackError.message}`);
}
});

file.content = data;
}
}

return file.content!;
Expand Down Expand Up @@ -52,4 +66,4 @@ export async function updateGistFiles(
});

return gist;
}
}