Sha256: 4c42fb827aa9c709f12a56320d7acee7468488202752f151d03be17b8ff15020

Contents?: true

Size: 757 Bytes

Versions: 21

Compression:

Stored size: 757 Bytes

Contents

module Her
  module Middleware
    # This middleware will raise errors based on the response status
    # Same as Faraday::Response::RaiseError, except it will catch specific
    # errors codes rather than everything in 400..600
    class MnoeRaiseError < Faraday::Response::RaiseError
      def on_complete(env)
        case env[:status]
        when 407
          # mimic the behavior that we get with proxy requests with HTTPS
          raise Faraday::Error::ConnectionFailed,
                %(407 "Proxy Authentication Required ")
        when 502..504
          raise Faraday::Error::ConnectionFailed, response_values(env)
        when 401, 500
          raise Faraday::Error::ClientError, response_values(env)
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mno-enterprise-core-2.0.4 lib/her_extension/middleware/mnoe_raise_error.rb