class Cotoha::Error

Public Class Methods

from_response(response) click to toggle source
# File lib/cotoha/error.rb, line 3
def self.from_response(response)
  klass =
    case response.status
      when 400 then BadRequest
      when 401 then Unauthorized
      when 403 then Forbidden
      when 404 then NotFound
      when 400..499 then ClientError
      when 500 then InternalServerError
      when 502 then BadGateway
      when 503 then ServiceUnavailable
      when 500..599 then ServerError
      else nil
    end
  klass.new(response) if klass
end
new(response = nil) click to toggle source
Calls superclass method
# File lib/cotoha/error.rb, line 20
def initialize(response = nil)
  @response = response
  super(build_error_message)
end

Private Instance Methods

build_error_message() click to toggle source
# File lib/cotoha/error.rb, line 27
def build_error_message
  return nil if @response.nil?

  "#{@response.env.method.upcase} #{@response.env.url}: " \
  "#{@response.status} - #{@response.body}"
end