Sha256: 0c970404780bd7a42bcc810f8516ae25fa7277c7c17445e14a9f2eaa1d7a241a

Contents?: true

Size: 945 Bytes

Versions: 2

Compression:

Stored size: 945 Bytes

Contents

module Frenchy
  class Error < ::StandardError; end

  class RequestError < Error
    attr_reader :message, :request, :response

    def initialize(message=nil, request=nil, response=nil)
      @request, @response = request, response

      if message
        @message = message.respond_to?(:message) ? message.message : message
      elsif response.respond_to?(:code)
        @message = "The server responded with status #{response.code}"
        @message += "\n\n#{response.body.to_s}" if response.body.to_s != ""
      else
        @message = "An unknown error has occured"
      end

      @message += "\n\n#{request}" if request
    end

    def to_s
      @message
    end
  end

  class BadRequest < RequestError; end
  class NotFound < RequestError; end
  class InvalidResponse < RequestError; end
  class ServerError < RequestError; end
  class ServiceUnavailable < ServerError; end
  class TemporarilyUnavailable < ServerError; end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
frenchy-0.5.0 lib/frenchy/error.rb
frenchy-0.4.0 lib/frenchy/error.rb