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
}.freeze
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

Class Method Details

.from_response(body) ⇒ Ohmage::Error

Create a new error from an HTTP response

Parameters:

  • body (String)

Returns:



86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Ohmage::Error

Initializes a new Error object

Parameters:

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

Returns:



77
78
79
80
# File 'lib/ohmage/error.rb', line 77

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