Exception: Traitify::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



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

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

Instance Attribute Details

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Class Method Details

.from(response) ⇒ Object



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

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

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

    klass.new(response)
  end
end

Instance Method Details

#errorsObject



24
25
26
# File 'lib/traitify/error.rb', line 24

def errors
  response.body
end