Skip to content

Commit

Permalink
Better catch redirect errors (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinred authored Nov 17, 2024
1 parent bdd3202 commit a95a365
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,43 @@ const moduleExports = () => {
})),
];

return builder
.getAll("url-redirects", {
apiKey:
process.env.NEXT_PUBLIC_BUILDER_API_KEY ||
"ce0c7323a97a4d91bd0baa7490ec9139",
options: { noTargeting: true },
cachebust: true,
})
.then(
(results) => [
...existingRedirects,
...results
.filter((content) => {
const data = (content || {}).data || {};
return !!(data.sourceUrl && data.destinationUrl);
})
.map(({ data }) => ({
source: data.sourceUrl,
destination: data.destinationUrl,
permanent: !!data.permanentRedirect,
})),
],
(error) => {
try {
return builder
.getAll("url-redirects", {
apiKey:
process.env.NEXT_PUBLIC_BUILDER_API_KEY ||
"ce0c7323a97a4d91bd0baa7490ec9139",
options: { noTargeting: true },
cachebust: true,
})
.then((results) => {
try {
return [
...existingRedirects,
...results
.filter((content) => {
const data = (content || {}).data || {};
return !!(data.sourceUrl && data.destinationUrl);
})
.map(({ data }) => ({
source: data.sourceUrl,
destination: data.destinationUrl,
permanent: !!data.permanentRedirect,
})),
];
} catch (error) {
console.log("Error processing redirects", error);
return existingRedirects;
}
})
.catch((error) => {
console.log("Error setting up redirects", error);
return existingRedirects;
},
);
});
} catch (error) {
console.log("Error fetching redirects from Builder:", error);
return existingRedirects;
}
},
webpack(config) {
config.module.rules.push({
Expand Down

0 comments on commit a95a365

Please sign in to comment.