Exception: Ohmage::Error

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

Constant Summary collapse

ClientError =
Class.new(self)
BadRequest =
Class.new(ClientError)
Unauthorized =
Class.new(ClientError)
NotFound =
Class.new(ClientError)
NotAcceptable =
Class.new(ClientError)
InvalidToken =
Class.new(ClientError)
InvalidParameter =
Class.new(ClientError)
MobilityException =
Class.new(ClientError)
SurveyException =
Class.new(ClientError)
CampaignException =
Class.new(ClientError)
ImageException =
Class.new(ClientError)
ClassException =
Class.new(ClientError)
UserException =
Class.new(ClientError)
CatchAll =
Class.new(ClientError)
ServerError =
Class.new(self)
InternalServerError =
Class.new(ServerError)
BadGateway =
Class.new(ServerError)
ServiceUnavailable =
Class.new(ServerError)
GatewayTimeout =
Class.new(ServerError)
ERRORS =
{
  888 => Ohmage::Error::CatchAll, # just, i don't know, catch 'em all.
  400 => Ohmage::Error::BadRequest,
  401 => Ohmage::Error::Unauthorized,
  404 => Ohmage::Error::NotFound,
  405 => Ohmage::Error::Unauthorized,
  406 => Ohmage::Error::NotAcceptable,
  500 => Ohmage::Error::InternalServerError,
  502 => Ohmage::Error::BadGateway,
  503 => Ohmage::Error::ServiceUnavailable,
  504 => Ohmage::Error::GatewayTimeout,
}
STRING_ERRORS =

How ugly is this??

{
  '0100' => Ohmage::Error::InternalServerError,
  '0101' => Ohmage::Error::InternalServerError,
  # Auth
  '0200' => Ohmage::Error::Unauthorized,
  '0201' => Ohmage::Error::Unauthorized,
  '0202' => Ohmage::Error::Unauthorized,
  '0203' => Ohmage::Error::InvalidToken,
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', code = nil) ⇒ Ohmage::Error

Initializes a new Error object

Parameters:

  • message (Exception, String) (defaults to: '')
  • rate_limit (Hash)
  • code (Integer) (defaults to: nil)


106
107
108
109
# File 'lib/ohmage/error.rb', line 106

def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Class Method Details

.from_response(body) ⇒ Ohmage::Error

Create a new error from an HTTP response

Parameters:

  • body (String)

Returns:



75
76
77
78
79
80
81
82
83
# File 'lib/ohmage/error.rb', line 75

def from_response(body)
  message, code = parse_error(body)
  # ohmage returns own error codes in body and as strings.
  if code.is_a? String
    new(message, 888)
  else
    new(message, code)
  end
end