Sha256: 01f085a83350553704a37c9fe03b250b599730a94fd977872af3b2fd7c496367

Contents?: true

Size: 813 Bytes

Versions: 5

Compression:

Stored size: 813 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::Error::ResourceNotFound, response_values(env)
          when 407
            # mimic the behavior that we get with proxy requests with HTTPS
            raise Faraday::Error::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

5 entries across 5 versions & 1 rubygems

Version Path
strava-ruby-client-0.3.2 lib/strava/web/raise_error.rb
strava-ruby-client-0.3.1 lib/strava/web/raise_error.rb
strava-ruby-client-0.3.0 lib/strava/web/raise_error.rb
strava-ruby-client-0.2.0 lib/strava/web/raise_error.rb
strava-ruby-client-0.1.0 lib/strava/web/raise_error.rb