Sha256: adcf5e95d49dd243a7613243af155c08ec9c91942398c5b132754c7b6592a9d2

Contents?: true

Size: 829 Bytes

Versions: 16

Compression:

Stored size: 829 Bytes

Contents

module Restfully
  module HTTP
    class Error < Restfully::Error
      STATUS_CODES = {
        400 => "Bad Request",
        401 => "Authorization Required",
        403 => "Forbiden",
        406 => "Not Acceptable"        
      }
      
      attr_reader :response
      def initialize(response)
        @response = response
        response_body = response.body rescue response.raw_body
        if response_body.kind_of?(Hash)
          message = "#{response.status} #{response_body['title']}. #{response_body['message']}"
        else
          message = "#{response.status} #{STATUS_CODES[response.status] || (response_body[0..100]+"...")}"
        end
        super(message)
      end
    end
    class ClientError < Restfully::HTTP::Error; end
    class ServerError < Restfully::HTTP::Error; end
  end
end
      
      

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
restfully-0.6.3 lib/restfully/http/error.rb
restfully-0.6.2 lib/restfully/http/error.rb
restfully-0.6.1 lib/restfully/http/error.rb
restfully-0.6.0 lib/restfully/http/error.rb
restfully-0.5.10 lib/restfully/http/error.rb
restfully-0.5.9 lib/restfully/http/error.rb
restfully-0.5.8 lib/restfully/http/error.rb
restfully-0.5.7 lib/restfully/http/error.rb
restfully-0.5.6 lib/restfully/http/error.rb
restfully-0.5.5 lib/restfully/http/error.rb
restfully-0.5.4 lib/restfully/http/error.rb
restfully-0.5.3 lib/restfully/http/error.rb
restfully-0.5.2 lib/restfully/http/error.rb
restfully-0.5.1 lib/restfully/http/error.rb
restfully-0.5.0 lib/restfully/http/error.rb
restfully-0.4.1 lib/restfully/http/error.rb