Sha256: b6216b66f2cdc6436588b9927c710f4e45d5a9ebb286a3fe7a00ddfefb3065d3

Contents?: true

Size: 799 Bytes

Versions: 3

Compression:

Stored size: 799 Bytes

Contents

module Strava
  module Web
    module Response
      class RaiseError < ::Faraday::Response::Middleware
        ClientErrorStatuses = (400...600).freeze

        def on_complete(env)
          case env[:status]
          when 404
            raise Faraday::ResourceNotFound, response_values(env)
          when 407
            # mimic the behavior that we get with proxy requests with HTTPS
            raise Faraday::ConnectionFailed, %(407 "Proxy Authentication Required ")
          when ClientErrorStatuses
            raise Strava::Errors::Fault, response_values(env)
          end
        end

        def response_values(env)
          {
            status: env.status,
            headers: env.response_headers,
            body: env.body
          }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strava-ruby-client-0.4.2 lib/strava/web/raise_error.rb
strava-ruby-client-0.4.1 lib/strava/web/raise_error.rb
strava-ruby-client-0.4.0 lib/strava/web/raise_error.rb