class Freshly::Error

Attributes

response[R]

Public Class Methods

from_response(response) click to toggle source
# File lib/freshly/error.rb, line 5
def self.from_response response
  status  = response[:status].to_i
  body    = response[:body].to_s
  headers = response[:response_headers]

  if klass =  case status
              when 400      then Freshly::BadRequest
              when 401      then Freshly::AuthenticationFailed
              when 403      then Freshly::AccessDenied
              when 404      then Freshly::NotFound
              when 405      then Freshly::MethodNotAllowed
              when 406      then Freshly::NotAcceptable
              when 409      then Freshly::Conflict
              when 415      then Freshly::UnsupportedMediaType
              when 429      then Freshly::RateLimitExceeded
              when 400..499 then Freshly::ClientError
              when 500      then Freshly::InternalServerError
              when 501      then Freshly::NotImplemented
              when 502      then Freshly::BadGateway
              when 503      then Freshly::ServiceUnavailable
              when 500..599 then Freshly::ServerError
              end

    klass.new(response)
  end
end
new(response=nil) click to toggle source
Calls superclass method
# File lib/freshly/error.rb, line 32
def initialize(response=nil)
  @response = response
  super(build_error_message)
end

Public Instance Methods

build_error_message() click to toggle source
# File lib/freshly/error.rb, line 37
def build_error_message
  "something went wrong"
end