class Simplewoo::Error

Attributes

response[RW]

Public Class Methods

from(response) click to toggle source
# File lib/simplewoo/error.rb, line 6
def self.from(response)
  status  = response.status

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

  klass.new(response)
  end
end
new(response) click to toggle source
Calls superclass method
# File lib/simplewoo/error.rb, line 20
def initialize(response)
  @response = response
  super(error_message)
end

Public Instance Methods

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

Private Instance Methods

error_message() click to toggle source
# File lib/simplewoo/error.rb, line 30
def error_message
  message =  "#{response.env[:method].upcase} "
  message << "#{response.env[:url].to_s} | "
  message << "#{response.status}: "
  message << "#{response.body.map{|k,v| "#{k}: #{v.first}"}.join(", ")}"
  message
end