Exception: Wikirate4ruby::Error

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

Constant Summary collapse

Wikirate4rubyError =
Class.new(self)
ParsingError =

Raised when a Parsing error is occured

Class.new(self)
IncompatibleCardTypeError =

Raised when an Incompatible Card Type is given as a type when try to parse an API response

Class.new(ParsingError)
ClientError =

Raised when Wikirate returns a 4xx HTTP status code

Class.new(self)
BadRequest =

Raised when Wikirate returns the HTTP status code 400

Class.new(ClientError)
Unauthorized =

Raised when Wikirate returns the HTTP status code 401

Class.new(ClientError)
Forbidden =

Raised when Wikirate returns the HTTP status code 403

Class.new(ClientError)
RequestEntityTooLarge =

Raised when Wikirate returns the HTTP status code 413

Class.new(ClientError)
NotFound =

Raised when Wikirate returns the HTTP status code 404

Class.new(ClientError)
NotAcceptable =

Raised when Wikirate returns the HTTP status code 406

Class.new(ClientError)
UnprocessableEntity =

Raised when Wikirate returns the HTTP status code 422

Class.new(ClientError)
TooManyRequests =

Raised when Wikirate returns the HTTP status code 429

Class.new(ClientError)
ServerError =

Raised when Wikirate returns a 5xx HTTP status code

Class.new(self)
InternalServerError =

Raised when Wikirate returns the HTTP status code 500

Class.new(ServerError)
BadGateway =

Raised when Wikirate returns the HTTP status code 502

Class.new(ServerError)
ServiceUnavailable =

Raised when Wikirate returns the HTTP status code 503

Class.new(ServerError)
GatewayTimeout =

Raised when Wikirate returns the HTTP status code 504

Class.new(ServerError)
TimeoutError =

Raised when an operation subject to timeout takes too long

Class.new(self)
HTTP_ERRORS =
{
  400 => Wikirate4ruby::Error::BadRequest,
  401 => Wikirate4ruby::Error::Unauthorized,
  403 => Wikirate4ruby::Error::Forbidden,
  404 => Wikirate4ruby::Error::NotFound,
  406 => Wikirate4ruby::Error::NotAcceptable,
  413 => Wikirate4ruby::Error::RequestEntityTooLarge,
  422 => Wikirate4ruby::Error::UnprocessableEntity,
  429 => Wikirate4ruby::Error::TooManyRequests,
  500 => Wikirate4ruby::Error::InternalServerError,
  502 => Wikirate4ruby::Error::BadGateway,
  503 => Wikirate4ruby::Error::ServiceUnavailable,
  504 => Wikirate4ruby::Error::GatewayTimeout
}.freeze
PARSING_ERRORS =
{
  'IncompatibleCardType' => Wikirate4ruby::Error::IncompatibleCardTypeError
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Error object

Parameters:

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


93
94
95
96
# File 'lib/wikirate4ruby/error.rb', line 93

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

Instance Attribute Details

#codeInteger (readonly)

Returns:

  • (Integer)


5
6
7
# File 'lib/wikirate4ruby/error.rb', line 5

def code
  @code
end

Class Method Details

.from_processing_response(error) ⇒ Object



81
82
83
84
85
# File 'lib/wikirate4ruby/error.rb', line 81

def from_processing_response(error)
  klass = PARSING_ERRORS[error[:name]] || self
  message = error[:message]
  klass.new(message)
end