Exception: Knock::KnockError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message: nil, error: nil, error_description: nil, http_status: nil, request_id: nil) ⇒ KnockError

Returns a new instance of KnockError.



6
7
8
9
10
11
12
# File 'lib/knock/errors.rb', line 6

def initialize(message: nil, error: nil, error_description: nil, http_status: nil, request_id: nil)
  @message = message
  @error = error
  @error_description = error_description
  @http_status = http_status
  @request_id = request_id
end

Instance Attribute Details

#http_statusObject (readonly)

Returns the value of attribute http_status.



3
4
5
# File 'lib/knock/errors.rb', line 3

def http_status
  @http_status
end

#request_idObject (readonly)

Returns the value of attribute request_id.



4
5
6
# File 'lib/knock/errors.rb', line 4

def request_id
  @request_id
end

Instance Method Details

#to_sObject



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

def to_s
  status_string = @http_status.nil? ? "" : "Status #{@http_status}, "
  id_string = @request_id.nil? ? "" : " - request ID: #{@request_id}"

  if @error && @error_description
    error_string = "error: #{@error}, error_description: #{@error_description}"
    "#{status_string}#{error_string}#{id_string}"
  elsif @error
    "#{status_string}#{@error}#{id_string}"
  else
    "#{status_string}#{@message}#{id_string}"
  end
end