Exception: Subordinate::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error


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

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

Instance Attribute Details

#responseObject

Returns the value of attribute response


4
5
6
# File 'lib/subordinate/error.rb', line 4

def response
  @response
end

Class Method Details

.from(response) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/subordinate/error.rb', line 6

def self.from(response)
  status  = response.status

  if klass = case status
             when 400 then Subordinate::BadRequest
             when 401 then Subordinate::Unauthorized
             when 404 then Subordinate::NotFound
             when 422 then Subordinate::UnprocessableEntity
             when 500 then Subordinate::InternalServerError
             end

    klass.new(response)
  end
end