Sha256: d2b4d5c9c6a393edcc759434bd6a196e31c1a098e4311c6473391ed95043b87f

Contents?: true

Size: 989 Bytes

Versions: 8

Compression:

Stored size: 989 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 Slideshare::InternalServerError, error_message(response, "Something is technically wrong.")
        when 502
          raise Slideshare::BadGateway, error_message(response, "Slideshare is down or being upgraded.")
        when 503
          raise Slideshare::ServiceUnavailable, error_message(response, "(__-){ Slideshare is over capacity.")
        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(' ')} Check http://status.twitter.com/ for updates on the status of the Twitter service."
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ruby-slideshare-0.1.7 lib/faraday/raise_http_5xx.rb
ruby-slideshare-0.1.6 lib/faraday/raise_http_5xx.rb
ruby-slideshare-0.1.5 lib/faraday/raise_http_5xx.rb
ruby-slideshare-0.1.3 lib/faraday/raise_http_5xx.rb
ruby-slideshare-0.1.2 lib/faraday/raise_http_5xx.rb
super-mega-slideshare-0.1.2 lib/faraday/raise_http_5xx.rb
super-mega-slideshare-0.1.1 lib/faraday/raise_http_5xx.rb
super-mega-slideshare-0.1.0 lib/faraday/raise_http_5xx.rb