Exception: Starwars::Error

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

Overview

Custom error class for rescuing from all Starwars errors

Defined Under Namespace

Classes: ArgumentError, BadRequest, ClientError, Forbidden, InternalServerError, NotFound, RequestTimeout, ServerError, ServiceUnavailableError, Unauthorized

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', _status = nil) ⇒ Starwars::Error

Initializes a new Error object

Examples:

Starwars::Error.new('I am your father', nil)

Parameters:

  • message (Exception, String) (defaults to: '')
  • _status (Exception, status) (defaults to: nil)


30
31
32
# File 'lib/starwars/error.rb', line 30

def initialize(message = '', _status = nil)
  super(message)
end

Class Method Details

.errorsHash

Return a hash of error classes

Examples:

get the total number of pages

Starwars::Error.errors

Returns:

  • (Hash)


10
11
12
13
14
15
16
17
18
19
# File 'lib/starwars/error.rb', line 10

def errors
  @errors ||=  {
    400 => Starwars::Error::BadRequest,
    401 => Starwars::Error::Unauthorized,
    403 => Starwars::Error::Forbidden,
    404 => Starwars::Error::NotFound,
    500 => Starwars::Error::InternalServerError,
    503 => Starwars::Error::ServiceUnavailableError
  }
end