Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
chore: Catch errors when fetching remote images
Browse files Browse the repository at this point in the history
While this wasn't an issue developing locally, this seems to be breaking
when building the site on Gatsby Cloud. Rather than raising a warning
and stopping the build, this will catch it and just submit a console
log.
  • Loading branch information
zstix committed Jul 1, 2022
1 parent 4e61a76 commit b62b8eb
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions plugins/gatsby-source-quickstarts/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,23 @@ exports.sourceNodes = async ({
for (const quickstart of QUICKSTARTS) {
const { name, id, logoUrl } = quickstart;

// if we have a logoUrl, fetch it and create a "File" node
const logoNode = logoUrl
? await createRemoteFileNode({
url: logoUrl,
parentNodeId: id,
createNode,
createNodeId,
getCache,
})
: null;
let logoNode = null;
try {
// if we have a logoUrl, fetch it and create a "File" node
logoNode = logoUrl
? await createRemoteFileNode({
url: logoUrl,
parentNodeId: id,
createNode,
createNodeId,
getCache,
})
: null;
} catch (e) {
// catch any errors when fetching image so that build still succeeds
console.log(`Unable to fetch logo for ${name}: ${logoUrl}`);
console.log(e);
}

// loop over the dashboard(s) for this quickstart, fetch all the
// screenshot(s) and create "File" nodes for each.
Expand Down Expand Up @@ -171,7 +178,7 @@ exports.sourceNodes = async ({
documentation: quickstart.documentation,
alerts: quickstart.alerts,
installPlans: quickstart.installPlans,
logo: logoNode,
logo: logoNode || null,
dashboards,
// gatsby fields
parent: null,
Expand Down Expand Up @@ -207,16 +214,22 @@ const getDashboardData = async ({
const screenshots = [];

for (const url of dashboard.screenshots) {
const screenshotNode = await createRemoteFileNode({
url,
parentNodeId: id,
createNode,
createNodeId,
getCache,
});

if (screenshotNode) {
screenshots.push(screenshotNode);
try {
const screenshotNode = await createRemoteFileNode({
url,
parentNodeId: id,
createNode,
createNodeId,
getCache,
});

if (screenshotNode) {
screenshots.push(screenshotNode);
}
} catch (e) {
// catch any errors when fetching image so that build still succeeds
console.log(`Unable to fetch screenshot for ${name}: ${url}`);
console.log(e);
}
}

Expand Down

0 comments on commit b62b8eb

Please sign in to comment.