Exception: Minisky::BadResponse

Inherits:
Error
  • Object
show all
Defined in:
lib/minisky/errors.rb

Overview

Raised when the API returns an error status code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, status_message, data) ⇒ BadResponse

Returns a new instance of BadResponse.

Parameters:

  • status (Integer)

    HTTP status code

  • status_message (String)

    HTTP status message

  • data (Hash, String)

    response data (JSON hash or string)



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/minisky/errors.rb', line 32

def initialize(status, status_message, data)
  @status = status
  @data = data

  message = if error_message
    "#{status} #{status_message}: #{error_message}"
  else
    "#{status} #{status_message}"
  end

  super(message)
end

Instance Attribute Details

#dataString, Hash (readonly)

Returns response data (JSON hash or string).

Returns:

  • (String, Hash)

    response data (JSON hash or string)



26
27
28
# File 'lib/minisky/errors.rb', line 26

def data
  @data
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



23
24
25
# File 'lib/minisky/errors.rb', line 23

def status
  @status
end

Instance Method Details

#error_messageString?

Returns human-readable error message from the response data.

Returns:

  • (String, nil)

    human-readable error message from the response data



51
52
53
# File 'lib/minisky/errors.rb', line 51

def error_message
  @data['message'] if @data.is_a?(Hash)
end

#error_typeString?

Returns machine-readable error code from the response data.

Returns:

  • (String, nil)

    machine-readable error code from the response data



46
47
48
# File 'lib/minisky/errors.rb', line 46

def error_type
  @data['error'] if @data.is_a?(Hash)
end