class Traitify::Error

Attributes

response[RW]

Public Class Methods

from(response) click to toggle source
# File lib/traitify/error.rb, line 5
def self.from(response)
  if klass = case response.status
             when 400 then Traitify::BadRequest
             when 401 then Traitify::Unauthorized
             when 404 then Traitify::NotFound
             when 422 then Traitify::UnprocessableEntity
             when 500..505 then Traitify::ServerError
             end
    klass.new(response)
  end
end
new(response) click to toggle source
Calls superclass method
# File lib/traitify/error.rb, line 17
def initialize(response)
  @response = response
  super(error_message)
end

Public Instance Methods

errors() click to toggle source
# File lib/traitify/error.rb, line 22
def errors
  response.body
end

Private Instance Methods

error_message() click to toggle source
# File lib/traitify/error.rb, line 27
def error_message
  message =  "#{response.method.upcase} | "
  message << "#{response.url.to_s} | "
  message << "#{response.status} | "
  message << (response.body.is_a?(Hash) ?
    "#{response.body["message"]}" : "#{response.body.first["message"]}")
  message
end