fix locale-utils unsupported lang uncaught err

This commit is contained in:
Amri Toufali 2022-08-26 09:40:25 -07:00
Родитель 155cf4cf39
Коммит 99681c7c60
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 75269D7487754F5D
3 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

@ -122,10 +122,12 @@ function previewEmail2022 (req, res) {
function sendTestEmail (data) {
return async function (req, res) {
const subject = LocaleUtils.fluentFormat(req.supportedLocales, data.subjectId)
// const supportedLocales = [req.user.signup_language, 'en'].filter(Boolean) // filter potential nullish signup_language, fallback to en
const supportedLocales = req.supportedLocales // this varies from send-email-to-unresolved-breach-subscribers.js (the line above) in order for QA to switch lang from browser
const subject = LocaleUtils.fluentFormat(supportedLocales, data.subjectId)
const context = {
whichPartial: data.whichPartial,
supportedLocales: req.supportedLocales,
supportedLocales,
primaryEmail: req.user.primary_email,
breachStats: req.user.breach_stats
}

Просмотреть файл

@ -67,9 +67,11 @@ const LocaleUtils = {
fluentFormat (supportedLocales, id, args = null, errors = null) {
for (const locale of supportedLocales) {
const bundle = fluentBundles[locale]
if (bundle.hasMessage(id)) {
try {
const message = bundle.getMessage(id)
return bundle.format(message, args)
} catch (e) {
continue
}
}
return id

Просмотреть файл

@ -6,7 +6,7 @@ async function sendUnresolvedBreachEmails () {
const subscribers = await DB.getSubscribersWithUnresolvedBreaches()
subscribers.forEach(async subscriber => {
const supportedLocales = [subscriber.signup_language, 'en'].filter(Boolean) // filter potential nullish signup_language
const supportedLocales = [subscriber.signup_language, 'en'].filter(Boolean) // filter potential nullish signup_language, fallback to en
const subject = LocaleUtils.fluentFormat(supportedLocales, 'email-unresolved-heading')
await EmailUtils.sendEmail(subscriber.primary_email, subject, 'email-2022',