Exception: Odnoklassniki::Error

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

Overview

Custom error class for rescuing from all Odnoklassniki errors

Defined Under Namespace

Modules: Code

Constant Summary collapse

ClientError =

Raised when Odnoklassniki returns a 2xx HTTP status code

Class.new(self)
BadRequest =

Raised when Odnoklassniki returns the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised when Odnoklassniki returns the HTTP status code 401

Class.new(ClientError)
Forbidden =

Raised when Odnoklassniki returns the HTTP status code 403

Class.new(ClientError)
NotFound =

Raised when Odnoklassniki returns the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised when Odnoklassniki returns the HTTP status code 406

Class.new(ClientError)
UnprocessableEntity =

Raised when Odnoklassniki returns the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised when Odnoklassniki returns the HTTP status code 429

Class.new(ClientError)
ServerError =

Raised when Odnoklassniki returns a 5xx HTTP status code

Class.new(self)
InternalServerError =

Raised when Odnoklassniki returns the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised when Odnoklassniki returns the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised when Odnoklassniki returns the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised when Odnoklassniki returns the HTTP status code 504

Class.new(ServerError)
ERRORS =
{
  200 => Odnoklassniki::Error::ClientError,
  400 => Odnoklassniki::Error::BadRequest,
  401 => Odnoklassniki::Error::Unauthorized,
  403 => Odnoklassniki::Error::Forbidden,
  404 => Odnoklassniki::Error::NotFound,
  406 => Odnoklassniki::Error::NotAcceptable,
  422 => Odnoklassniki::Error::UnprocessableEntity,
  429 => Odnoklassniki::Error::TooManyRequests,
  500 => Odnoklassniki::Error::InternalServerError,
  502 => Odnoklassniki::Error::BadGateway,
  503 => Odnoklassniki::Error::ServiceUnavailable,
  504 => Odnoklassniki::Error::GatewayTimeout,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Error object

Parameters:

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


177
178
179
180
# File 'lib/odnoklassniki/error.rb', line 177

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

Instance Attribute Details

#codeInteger (readonly)

Returns:

  • (Integer)


6
7
8
# File 'lib/odnoklassniki/error.rb', line 6

def code
  @code
end

Class Method Details

.from_response(body) ⇒ Odnoklassniki::Error

Create a new error from an HTTP response

Parameters:

  • response (HTTP::Response)

Returns:



160
161
162
# File 'lib/odnoklassniki/error.rb', line 160

def from_response(body)
  new(*parse_error(body))
end