Exception: Commons::Errors::ErrorBase

Inherits:
StandardError
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/commons/errors/error_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, backtrace = nil, status: :internal_server_error, code: I18n.t('status_code.IER5000_internal_server_error.code'), title: I18n.t('status_code.IER5000_internal_server_error.title'), detail: I18n.t('status_code.IER5000_internal_server_error.detail'), meta: {}) ⇒ ErrorBase

Returns a new instance of ErrorBase.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/commons/errors/error_base.rb', line 29

def initialize(message = nil,
               backtrace = nil,
               status: :internal_server_error,
               code: I18n.t('status_code.IER5000_internal_server_error.code'),
               title: I18n.t('status_code.IER5000_internal_server_error.title'),
               detail: I18n.t('status_code.IER5000_internal_server_error.detail'),
               meta: {})

  @message = message
  @backtrace = backtrace
  @title = title
  @detail = detail
  @code = code
  @status = status
  @meta = meta
  @meta.merge!(message: message) unless @meta.nil? || @message.nil?
  @meta = nil if @meta.blank?
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def backtrace
  @backtrace
end

#codeObject (readonly)

Returns the value of attribute code.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def code
  @code
end

#detailObject (readonly)

Returns the value of attribute detail.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def detail
  @detail
end

#messageObject (readonly)

Returns the value of attribute message.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def message
  @message
end

#metaObject (readonly)

Returns the value of attribute meta.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def meta
  @meta
end

#titleObject (readonly)

Returns the value of attribute title.



27
28
29
# File 'lib/commons/errors/error_base.rb', line 27

def title
  @title
end

Instance Method Details

#statusObject



59
60
61
# File 'lib/commons/errors/error_base.rb', line 59

def status
  Rack::Utils::SYMBOL_TO_STATUS_CODE[@status]
end

#to_hashObject

returns the error as its hash representation



49
50
51
52
53
54
55
56
57
# File 'lib/commons/errors/error_base.rb', line 49

def to_hash
  {
    code: code,
    title: title,
    status: status,
    detail: detail,
    meta: meta
  }
end