Class: Localeapp::ExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/localeapp/exception_handler.rb

Class Method Summary collapse

Class Method Details

.call(exception, locale, key_or_keys, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/localeapp/exception_handler.rb', line 3

def self.call(exception, locale, key_or_keys, options)
  keys = Array(key_or_keys).map { |key| ERB::Util.html_escape(key.to_s) }
  scoped_keys = keys.map { |key| [options[:scope], key].compact.join(".") }
  Localeapp.log(exception.message)
  # Which exact exception is set up by our i18n shims
  if exception.is_a? Localeapp::I18nMissingTranslationException
    Localeapp.log("Detected missing translation for key(s) #{scoped_keys.inspect}")

    keys.each do |key|
      Localeapp.missing_translations.add(locale, key, nil, options || {})
    end

    [locale, scoped_keys].join(', ')
  else
    Localeapp.log('Raising exception')
    raise
  end
end