Only log error on first occurrence of missing substitution (#9096)

A missing substitution for a localized message will now only log an
error upon the first occurrence. Further errors are generally not
useful.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent 1582855e28
commit b7715f6e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      ui/app/helpers/utils/i18n-helper.js

@ -6,6 +6,7 @@ import * as Sentry from '@sentry/browser'
const warned = {}
const missingMessageErrors = {}
const missingSubstitutionErrors = {}
/**
* Returns a localized message for the given key
@ -55,7 +56,11 @@ export const getMessage = (localeCode, localeMessages, key, substitutions) => {
return part
}
const substituteIndex = Number(subMatch[1]) - 1
if (substitutions[substituteIndex] == null) {
if (substitutions[substituteIndex] == null && !missingSubstitutionErrors[localeCode]?.[key]) {
if (!missingSubstitutionErrors[localeCode]) {
missingSubstitutionErrors[localeCode] = {}
}
missingSubstitutionErrors[localeCode][key] = true
const error = new Error(`Insufficient number of substitutions for message: '${phrase}'`)
log.error(error)
Sentry.captureException(error)

Loading…
Cancel
Save