Exception: Consulkit::Error

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

Overview

An error returned from the Consul API.

Direct Known Subclasses

Client, Server

Defined Under Namespace

Classes: ACLNotFound, BadRequest, Client, Forbidden, NotFound, Server

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



7
8
9
10
11
# File 'lib/consulkit/error.rb', line 7

def initialize(response)
  @response = response

  super(error_message)
end

Class Method Details

.from_response(response) ⇒ Object

Returns the appropriate Consulkit::Error subclass based on the status and response message, or nil if the response is not an error.

Parameters:

  • response (Hash)

    the HTTP response

Returns:

  • Consulkit::Error



19
20
21
22
23
# File 'lib/consulkit/error.rb', line 19

def self.from_response(response)
  return unless (error_class = error_class_for(response))

  error_class.new(response)
end

Instance Method Details

#response_bodyObject



33
34
35
# File 'lib/consulkit/error.rb', line 33

def response_body
  @response.response_body
end

#response_headersObject



29
30
31
# File 'lib/consulkit/error.rb', line 29

def response_headers
  @response.response_headers
end

#response_statusObject



25
26
27
# File 'lib/consulkit/error.rb', line 25

def response_status
  @response.status
end