Sha256: 074cdd5de33e10f962a8835e5df179906cb93717a32769f4578eb77a306806ba

Contents?: true

Size: 788 Bytes

Versions: 10

Compression:

Stored size: 788 Bytes

Contents

require 'faraday'

# @private
module Faraday
  # @private
  class Response::RaiseHttp5xx < Response::Middleware
    def self.register_on_complete(env)
      env[:response].on_complete do |response|
        case response[:status].to_i
        when 500
          raise Instagram::InternalServerError, error_message(response, "Something is technically wrong.")
        when 503
          raise Instagram::ServiceUnavailable, error_message(response, "Instagram is rate limiting your requests.")
        end
      end
    end

    def initialize(app)
      super
      @parser = nil
    end

    private

    def self.error_message(response, body=nil)
      "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
    end
  end
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
instagram-0.8.2 lib/faraday/raise_http_5xx.rb
instagram-fixed-0.8.1 lib/faraday/raise_http_5xx.rb
instagram-fixed-0.8 lib/faraday/raise_http_5xx.rb
instagram-innonate-0.8 lib/faraday/raise_http_5xx.rb
instagram-0.8 lib/faraday/raise_http_5xx.rb
instagram-0.7 lib/faraday/raise_http_5xx.rb
instagram-0.6.2 lib/faraday/raise_http_5xx.rb
localist-instagvram-0.6.2 lib/faraday/raise_http_5xx.rb
instagram-0.6.1 lib/faraday/raise_http_5xx.rb
instagram-0.6 lib/faraday/raise_http_5xx.rb