class Ohmage::Error

Constants

BadGateway
BadRequest
CampaignException
CatchAll
ClassException
ClientError
ERRORS
GatewayTimeout
ImageException
InternalServerError
InvalidParameter
InvalidToken
MobilityException
NotAcceptable
NotFound
STRING_ERRORS

How ugly is this??

ServerError
ServiceUnavailable
SurveyException
Unauthorized
UserException

Public Class Methods

from_response(body) click to toggle source

Create a new error from an HTTP response

@param body [String] @return [Ohmage::Error]

# File lib/ohmage/error.rb, line 86
def from_response(body)
  message, code = parse_error(body)
  # ohmage returns own error codes in body and as strings.
  if code.is_a? String
    # some bug in catchall already sets this?
    # error class really needs a refactor.
    new(message)
  else
    new(message, code)
  end
end
initialize(message = '', code = nil) click to toggle source

Initializes a new Error object

@param message [Exception, String] @param rate_limit [Hash] @param code [Integer] @return [Ohmage::Error]

Calls superclass method
# File lib/ohmage/error.rb, line 77
def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Private Class Methods

extract_message_from_errors(body) click to toggle source
# File lib/ohmage/error.rb, line 108
def extract_message_from_errors(body)
  first = Array(body[:errors]).first
  [first[:text], first[:code]]
end
parse_error(body) click to toggle source
# File lib/ohmage/error.rb, line 100
def parse_error(body)
  if body.nil? || body.empty?
    ['', nil]
  elsif body[:errors]
    extract_message_from_errors(body)
  end
end