Module: Colore::Errors

Defined in:
lib/colore/errors.rb

Overview

Module for handling Colore-specific errors.

Defined Under Namespace

Classes: APIError, ClientError, ColoreUnavailable, ServerError

Class Method Summary collapse

Class Method Details

.from(hash, body) ⇒ APIError

Creates an appropriate error object from the given hash.

Parameters:

  • hash (Hash, nil)

    the error details from the API response

  • body (String)

    the response body

Returns:

  • (APIError)

    the created error object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/colore/errors.rb', line 43

def self.from(hash, body)
  if hash.nil?
    ServerError.new(0, 'Unknown error (see response_body)', nil, body)
  else
    case hash['status']
    when 400..499
      ClientError.new(hash['status'].to_i, hash['description'], hash['backtrace'], body)
    else
      ServerError.new(hash['status'].to_i, hash['description'], hash['backtrace'], body)
    end
  end
end