Exception: Mackerel::Error

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

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



18
19
20
21
# File 'lib/mackerel/error.rb', line 18

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

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/mackerel/error.rb', line 3

def response
  @response
end

Class Method Details

.from_response(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mackerel/error.rb', line 5

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

  klass = case status
          when 400      then BadRequest
          when 400..499 then ClientError
          when 500      then InternalServerError
          when 500..599 then ServerError
          end

  klass.new(response) if klass
end