Exception: ErrorsHelper::Base

Inherits:
StandardError
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/errors_helper/base.rb

Direct Known Subclasses

BadRequest, NotFound, UnprocessableEntity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: ErrorsHelper.build_response(code: '99')[:message], code: ErrorsHelper.build_response(code: '99')[:code], status: nil) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
# File 'lib/errors_helper/base.rb', line 11

def initialize(message: ErrorsHelper.build_response(code: '99')[:message],
               code: ErrorsHelper.build_response(code: '99')[:code],
               status: nil)
  @message = message
  @code = code
  @status = status
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/errors_helper/base.rb', line 9

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/errors_helper/base.rb', line 9

def message
  @message
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/errors_helper/base.rb', line 32

def inspect
  "[Code: #{code}] #{message}"
end

#statusObject



28
29
30
# File 'lib/errors_helper/base.rb', line 28

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

#to_hashObject Also known as: to_h



19
20
21
22
23
24
# File 'lib/errors_helper/base.rb', line 19

def to_hash
  {
    message: message,
    code: code
  }.compact
end