Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
gemfury / lib / gemfury / client / middleware.rb
Size: Mime:
# frozen_string_literal: true

module Gemfury
  class Client
    class Handle503 < Faraday::Middleware
      def call(env)
        # This prevents errors in ParseJson
        @app.call(env).on_complete do |out|
          out[:body] = '' if out[:status] == 503
        end
      end
    end

    class ParseJson < Faraday::Middleware
      def parse(body)
        body =~ /\A\s*\z/ ? nil : MultiJson.decode(body)
      end

      def on_complete(response)
        ok = response.request_headers['Accept'] =~ /json\z/
        response.body = parse(response.body) if ok
      end
    end
  end
end