Exception: AuxiliaryRails::Application::Error Abstract

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/auxiliary_rails/application/error.rb

Overview

This class is abstract.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, context: {}, exc: nil, severity: nil) ⇒ Error

Returns a new instance of Error.



19
20
21
22
23
24
25
# File 'lib/auxiliary_rails/application/error.rb', line 19

def initialize(message = nil, context: {}, exc: nil, severity: nil)
  super(message)

  self.context = default_context.merge(context || {})
  self.exc = exc
  self.severity = severity&.to_sym || default_severity
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



5
6
7
# File 'lib/auxiliary_rails/application/error.rb', line 5

def context
  @context
end

#excObject

Returns the value of attribute exc.



6
7
8
# File 'lib/auxiliary_rails/application/error.rb', line 6

def exc
  @exc
end

#severityObject

Returns the value of attribute severity.



6
7
8
# File 'lib/auxiliary_rails/application/error.rb', line 6

def severity
  @severity
end

Class Method Details

.i18n_scopeObject



9
10
11
# File 'lib/auxiliary_rails/application/error.rb', line 9

def i18n_scope
  "errors.#{name.underscore}"
end

.wrap(exc, context: {}, severity: nil) ⇒ self

Returns Wraps exception into a new ApplicationError object.

Returns:

  • (self)

    Wraps exception into a new ApplicationError object



14
15
16
# File 'lib/auxiliary_rails/application/error.rb', line 14

def wrap(exc, context: {}, severity: nil)
  new(exc.message, context: context, exc: exc, severity: severity)
end

Instance Method Details

#default_contextObject



27
28
29
# File 'lib/auxiliary_rails/application/error.rb', line 27

def default_context
  {}
end

#default_severityObject



31
32
33
# File 'lib/auxiliary_rails/application/error.rb', line 31

def default_severity
  :error
end

#friendly_messageObject



35
36
37
38
39
# File 'lib/auxiliary_rails/application/error.rb', line 35

def friendly_message
  I18n.t(:default,
    scope: self.class.i18n_scope,
    default: 'We are sorry, but something went wrong.')
end

#reportObject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/auxiliary_rails/application/error.rb', line 41

def report
  raise NotImplementedError
end