Exception: Octoparts::ResponseError

Inherits:
Error
  • Object
show all
Defined in:
lib/octoparts/error.rb

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseError

Returns a new instance of ResponseError.



17
18
19
20
# File 'lib/octoparts/error.rb', line 17

def initialize(response)
  @response = response
  super(error_message)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/octoparts/error.rb', line 7

def self.from_response(response)
  status = response.status.to_i

  klass = case status
          when 400..499 then Octoparts::ClientError
          when 500..599 then Octoparts::ServerError
          end
  klass.new(response) unless klass.nil?
end

Instance Method Details

#error_messageObject



22
23
24
# File 'lib/octoparts/error.rb', line 22

def error_message
  "status: #{@response.status}, body: #{@response.body}"
end