Module: Cassette::Errors

Defined in:
lib/cassette/errors.rb,
lib/cassette/errors/not_a_customer.rb,
lib/cassette/errors/not_an_employee.rb

Defined Under Namespace

Classes: Base, NotACustomer, NotAnEmployee

Constant Summary collapse

TYPES =
{
  401 => :authorization_required,
  400 => :bad_request,
  403 => :forbidden,
  500 => :internal_server_error,
  404 => :not_found,
  412 => :precondition_failed
}

Class Method Summary collapse

Class Method Details

.error_class(name) ⇒ Object


26
27
28
# File 'lib/cassette/errors.rb', line 26

def self.error_class(name)
  "Cassette::Errors::#{name.to_s.camelize}".constantize
end

.raise_by_code(code) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/cassette/errors.rb', line 16

def self.raise_by_code(code)
  name = TYPES[code.to_i]

  if name
    fail error_class(name)
  else
    fail error_class(:internal_server_error)
  end
end