From 0d71dd7ca0c0c3178670a9882c34d180495a7031 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 23 Mar 2018 14:31:15 -0230 Subject: [PATCH] i18n helper fetchLocale handles 404 gracefully --- ui/i18n-helper.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ui/i18n-helper.js b/ui/i18n-helper.js index dc83f45c9..3ce24ddfb 100644 --- a/ui/i18n-helper.js +++ b/ui/i18n-helper.js @@ -25,10 +25,18 @@ const getMessage = (locale, key, substitutions) => { return phrase } -async function fetchLocale (localeName) { - const response = await fetch(`/_locales/${localeName}/messages.json`) - const locale = await response.json() - return locale +function fetchLocale (localeName) { + return new Promise((resolve, reject) => { + return fetch(`/_locales/${localeName}/messages.json`) + .then(response => response.json()) + .then( + locale => resolve(locale), + error => { + log.error(`failed to fetch ${localeName} locale because of ${error}`) + resolve({}) + } + ) + }) } module.exports = {