Skip to content

Commit

Permalink
Merge pull request #204 from karlpauls/203
Browse files Browse the repository at this point in the history
fix: Unhandled Promise Rejection in lib-franklin fetchPlaceholders
  • Loading branch information
trieloff committed Apr 20, 2023
2 parents b30b80c + b1b2c64 commit c67996a
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,26 @@ export async function fetchPlaceholders(prefix = 'default') {
const loaded = window.placeholders[`${prefix}-loaded`];
if (!loaded) {
window.placeholders[`${prefix}-loaded`] = new Promise((resolve, reject) => {
try {
fetch(`${prefix === 'default' ? '' : prefix}/placeholders.json`)
.then((resp) => resp.json())
.then((json) => {
const placeholders = {};
json.data.forEach((placeholder) => {
fetch(`${prefix === 'default' ? '' : prefix}/placeholders.json`)
.then((resp) => {
if (resp.ok) {
return resp.json();
}
throw new Error(`${resp.status}: ${resp.statusText}`);
}).then((json) => {
const placeholders = {};
json.data
.filter((placeholder) => placeholder.Key)
.forEach((placeholder) => {
placeholders[toCamelCase(placeholder.Key)] = placeholder.Text;
});
window.placeholders[prefix] = placeholders;
resolve();
});
} catch (error) {
// error loading placeholders
window.placeholders[prefix] = {};
reject();
}
window.placeholders[prefix] = placeholders;
resolve();
}).catch((error) => {
// error loading placeholders
window.placeholders[prefix] = {};
reject(error);
});
});
}
await window.placeholders[`${prefix}-loaded`];
Expand Down

0 comments on commit c67996a

Please sign in to comment.