Exception: DataSiftError

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

Overview

Custom error class for rescuing DataSift errors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_status = nil, http_body = nil, response_on_error = nil) ⇒ DataSiftError

Returns a new instance of DataSiftError.



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

def initialize(http_status = nil, http_body = nil, response_on_error = nil)
  @status = http_status
  @body   = http_body
  @response = response_on_error
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#messageObject



11
12
13
# File 'lib/errors.rb', line 11

def message
  @body.nil? ? @status : @body
end

#to_sObject



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

def to_s
  # If both body and status were provided then message is the body otherwise
  #   the status contains the message
  msg = !@body.nil? && !@status.nil? ? @body : @status
  # If body is nil then status is the message body so no status is included
  status_string = @body.nil? ? '' : "(Status #{@status}) "
  "#{status_string} : #{msg}"
end