Exception: Kabk::ApiError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/kabk/errors.rb

Overview

Defines standardized API errors that map to protocol error codes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code: "SERVER_ERROR", http_status: 500, fields: {}) ⇒ ApiError

Returns a new instance of ApiError.



8
9
10
11
12
13
# File 'lib/kabk/errors.rb', line 8

def initialize(message, code: "SERVER_ERROR", http_status: 500, fields: {})
  super(message)
  @code = code
  @http_status = http_status
  @fields = fields
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/kabk/errors.rb', line 6

def code
  @code
end

#fieldsObject (readonly)

Returns the value of attribute fields.



6
7
8
# File 'lib/kabk/errors.rb', line 6

def fields
  @fields
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



6
7
8
# File 'lib/kabk/errors.rb', line 6

def http_status
  @http_status
end

Instance Method Details

#to_hObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/kabk/errors.rb', line 15

def to_h
  {
    success: false,
    error: {
      code: @code,
      message: message,
      fields: @fields
    }
  }
end