Or post ES2017, without all the .then()s:
const doThing = async (url, fallback) => {
try {
const response = await fetch(url)
const notifications = await response.json()
return notifications.map((notification) => ({
...notification,
readableDate: new Date(notification.date * SECONDS).toGMTString(),
message: notification.message.replace(/</g, '<'),
sender: `https://example.com/users/${notification.username}`,
source: `https://example.com/${notification.sourceType}/${notification.sourceId}`,
icon: `https://example.com/assets/icons/${notification.sourceType}-small.svg`,
}))
} catch (error) {
console.log(error.message);
return fallback
}
}