Module: RestConnection::Errors

Defined in:
lib/rest_connection.rb

Defined Under Namespace

Classes: Accepted, BadGateway, BadRequest, Conflict, Continue, Created, ExpectationFailed, Forbidden, Found, GatewayTimeout, Gone, HTTPStatusError, InternalServerError, LengthRequired, MethodNotAllowed, MovedPermanently, MultipleChoices, NoContent, NonAuthoritativeInformation, NotAcceptable, NotFound, NotImplemented, NotModified, OK, PartialContent, PaymentRequired, PreconditionFailed, ProxyAuthenticationRequired, RequestEntityTooLarge, RequestTimeout, RequestURITooLong, RequestedRangeNotSatisfiable, ResetContent, SeeOther, ServiceUnavailable, SwitchingProtocols, TemporaryRedirect, Unauthorized, UnprocessableEntity, UnsupportedMediaType, UseProxy

Class Method Summary collapse

Class Method Details

.status_error(response) ⇒ Object

Messages for nicer exceptions, from rfc2616



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/rest_connection.rb', line 355

def self.status_error(response)
  @errors ||= {
    100 => [RestConnection::Errors::Continue, 'Continue'],
    101 => [RestConnection::Errors::SwitchingProtocols, 'Switching Protocols'],
    200 => [RestConnection::Errors::OK, 'OK'],
    201 => [RestConnection::Errors::Created, 'Created'],
    202 => [RestConnection::Errors::Accepted, 'Accepted'],
    203 => [RestConnection::Errors::NonAuthoritativeInformation, 'Non-Authoritative Information'],
    204 => [RestConnection::Errors::NoContent, 'No Content'],
    205 => [RestConnection::Errors::ResetContent, 'Reset Content'],
    206 => [RestConnection::Errors::PartialContent, 'Partial Content'],
    300 => [RestConnection::Errors::MultipleChoices, 'Multiple Choices'],
    301 => [RestConnection::Errors::MovedPermanently, 'Moved Permanently'],
    302 => [RestConnection::Errors::Found, 'Found'],
    303 => [RestConnection::Errors::SeeOther, 'See Other'],
    304 => [RestConnection::Errors::NotModified, 'Not Modified'],
    305 => [RestConnection::Errors::UseProxy, 'Use Proxy'],
    307 => [RestConnection::Errors::TemporaryRedirect, 'Temporary Redirect'],
    400 => [RestConnection::Errors::BadRequest, 'Bad Request'],
    401 => [RestConnection::Errors::Unauthorized, 'Unauthorized'],
    402 => [RestConnection::Errors::PaymentRequired, 'Payment Required'],
    403 => [RestConnection::Errors::Forbidden, 'Forbidden'],
    404 => [RestConnection::Errors::NotFound, 'Not Found'],
    405 => [RestConnection::Errors::MethodNotAllowed, 'Method Not Allowed'],
    406 => [RestConnection::Errors::NotAcceptable, 'Not Acceptable'],
    407 => [RestConnection::Errors::ProxyAuthenticationRequired, 'Proxy Authentication Required'],
    408 => [RestConnection::Errors::RequestTimeout, 'Request Timeout'],
    409 => [RestConnection::Errors::Conflict, 'Conflict'],
    410 => [RestConnection::Errors::Gone, 'Gone'],
    411 => [RestConnection::Errors::LengthRequired, 'Length Required'],
    412 => [RestConnection::Errors::PreconditionFailed, 'Precondition Failed'],
    413 => [RestConnection::Errors::RequestEntityTooLarge, 'Request Entity Too Large'],
    414 => [RestConnection::Errors::RequestURITooLong, 'Request-URI Too Long'],
    415 => [RestConnection::Errors::UnsupportedMediaType, 'Unsupported Media Type'],
    416 => [RestConnection::Errors::RequestedRangeNotSatisfiable, 'Request Range Not Satisfiable'],
    417 => [RestConnection::Errors::ExpectationFailed, 'Expectation Failed'],
    422 => [RestConnection::Errors::UnprocessableEntity, 'Unprocessable Entity'],
    500 => [RestConnection::Errors::InternalServerError, 'InternalServerError'],
    501 => [RestConnection::Errors::NotImplemented, 'Not Implemented'],
    502 => [RestConnection::Errors::BadGateway, 'Bad Gateway'],
    503 => [RestConnection::Errors::ServiceUnavailable, 'Service Unavailable'],
    504 => [RestConnection::Errors::GatewayTimeout, 'Gateway Timeout']
  }
  error, message = @errors[response.code.to_i] || [RestConnection::Errors::HTTPStatusError, 'Unknown']
  error.new("Invalid response HTTP code: #{response.code.to_i}: #{response.body}", response)
end