Sha256: 115231f58aa78d00346164a736b222eb41d63cd7932f788795243f266870dad1

Contents?: true

Size: 865 Bytes

Versions: 20

Compression:

Stored size: 865 Bytes

Contents

module RDStation
  class ErrorHandler
    class ExpiredAccessToken
      attr_reader :errors

      EXPIRED_TOKEN_ERROR = 'error="expired_token"'.freeze

      def initialize(errors)
        @errors = errors
      end

      def raise_error
        return if expired_token_errors.empty?
        raise RDStation::Error::ExpiredAccessToken, expired_token_errors.first
      end

      private

      def expired_token_errors
        errors.select do |error|
          error_header = error['headers']
          next unless error_header
          expired_token_error?(error_header)
        end
      end

      def expired_token_error?(error_header)
        auth_header = error_header['x-amzn-remapped-www-authenticate'] || error_header['www-authenticate']
        return unless auth_header
        auth_header.include?(EXPIRED_TOKEN_ERROR)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.9.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.8.2 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.8.1 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.8.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.7.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.6.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.5.3 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.5.2 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.5.1 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.5.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.4.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.3.1 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.3.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.2.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.1.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-2.0.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-1.2.1 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-1.2.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-1.1.0 lib/rdstation/error_handler/expired_access_token.rb
rdstation-ruby-client-1.0.1 lib/rdstation/error_handler/expired_access_token.rb