Sha256: ea2a0440221cb580427c69a1af8fdbac0f8df21f53333e72e7881b51f97b25c8

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 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 NotFound < RequestError; end
  class InvalidResponse < RequestError; end
  class ServerError < RequestError; end
  class ServiceUnavailable < ServerError; end
  class TemporarilyUnavailable < ServerError; end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
frenchy-0.3.0 lib/frenchy/error.rb
frenchy-0.2.9 lib/frenchy/error.rb
frenchy-0.2.8 lib/frenchy/error.rb