Exception: Common::Exceptions::BaseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/common/exceptions/base_error.rb

Overview

Base error class all others inherit from

Instance Method Summary collapse

Instance Method Details

#errorsObject

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/common/exceptions/base_error.rb', line 7

def errors
  raise NotImplementedError, 'Subclass of Error must implement errors method'
end

#i18n_dataObject (private)



38
39
40
# File 'lib/common/exceptions/base_error.rb', line 38

def i18n_data
  I18n.t(i18n_key)
end

#i18n_field(attribute, options) ⇒ Object (private)



42
43
44
45
46
# File 'lib/common/exceptions/base_error.rb', line 42

def i18n_field(attribute, options)
  I18n.t("#{i18n_key}.#{attribute}", **options)
rescue
  nil
end

#i18n_interpolated(options = {}) ⇒ Object (private)



48
49
50
51
# File 'lib/common/exceptions/base_error.rb', line 48

def i18n_interpolated(options = {})
  merge_values = options.map { |attribute, opts| [attribute, i18n_field(attribute, opts)] }.to_h
  i18n_data.merge(merge_values)
end

#i18n_keyObject (private)



34
35
36
# File 'lib/common/exceptions/base_error.rb', line 34

def i18n_key
  "common.exceptions.#{self.class.name.split('::').last.underscore}"
end

#log_to_sentry?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/common/exceptions/base_error.rb', line 28

def log_to_sentry?
  sentry_type != 'none'
end

#messageObject



18
19
20
# File 'lib/common/exceptions/base_error.rb', line 18

def message
  i18n_data[:title]
end

#sentry_typeObject

This determines how the exception should get logged to Sentry in adddition to available types from Sentry: ‘warn’, ‘info’, ‘error’ there is ‘none’ to not log to Sentry at all



24
25
26
# File 'lib/common/exceptions/base_error.rb', line 24

def sentry_type
  i18n_data[:sentry_type].presence || 'error'
end

#status_codeObject



11
12
13
14
15
16
# File 'lib/common/exceptions/base_error.rb', line 11

def status_code
  return if errors&.first.blank?
  return errors.first[:status]&.to_i if errors.first.is_a?(Hash)

  errors&.first&.status&.to_i
end