class SphereEngine::Error

Custom error class for rescuing from all SphereEngine errors

Constants

BadRequest

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

Raised when SphereEngine returns the HTTP status code 400

ERRORS
Unauthorized

Raised when SphereEngine returns the HTTP status code 401

Attributes

code[R]

@return [Integer]

Public Class Methods

from_response(body) click to toggle source

Create a new error from an HTTP response

@param body [String] @param headers [Hash] @return [SphereEngine::Error]

# File lib/sphere_engine/error.rb, line 36
def from_response(body)
  message, code = parse_error(body)
  new(message, code)
end
new(message = '', code = nil) click to toggle source

Initializes a new Error object

@param message [Exception, String] @param code [Integer] @return [SphereEngine::Error]

Calls superclass method
# File lib/sphere_engine/error.rb, line 12
def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Private Class Methods

parse_error(body) click to toggle source
# File lib/sphere_engine/error.rb, line 43
def parse_error(body)
  if body.nil? || body.empty?
    ['', nil]
  elsif  body["message"] || body[:message]
    [ body["message"] || body[:message], nil]
  end
end