Exception: SphereEngine::Error

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

Overview

Custom error class for rescuing from all SphereEngine errors

Constant Summary collapse

BadRequest =

ClientErrors(Raised when SphereEngine returns a 4xx HTTP status code)

Raised when SphereEngine returns the HTTP status code 400

Class.new(self)
Unauthorized =

Raised when SphereEngine returns the HTTP status code 401

Class.new(self)
ERRORS =
{
  400 => SphereEngine::Error::BadRequest,
  401 => SphereEngine::Error::Unauthorized
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initializes a new Error object

Parameters:

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


12
13
14
15
# File 'lib/sphere_engine/error.rb', line 12

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

Instance Attribute Details

#codeInteger (readonly)

Returns:

  • (Integer)


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

def code
  @code
end

Class Method Details

.from_response(body) ⇒ SphereEngine::Error

Create a new error from an HTTP response

Parameters:

  • body (String)
  • headers (Hash)

Returns:



36
37
38
39
# File 'lib/sphere_engine/error.rb', line 36

def from_response(body)
  message, code = parse_error(body)
  new(message, code)
end