we-promise/sure · error · Provider::IndexaCapital::ConfigurationError

Either API token or all three username/document/password cre

Error message

Either API token or all three username/document/password credentials are required

What it means

Raised as Provider::IndexaCapital::ConfigurationError when the Indexa Capital provider is configured with neither an API token nor the complete legacy triple (username, document, password). Indexa supports two auth modes: token auth (api_token alone) and credential auth (all three of username/document/password required together). validate_configuration! enforces at least one complete mode and fails fast when credentials are half-entered.

Source

Thrown at app/models/provider/indexa_capital.rb:116

    ].freeze

    MAX_RETRIES = 3
    INITIAL_RETRY_DELAY = 2 # seconds

    # Indexa Capital account numbers are 8-char alphanumeric (e.g., "LPYH3MCQ")
    def sanitize_account_number!(account_number)
      unless account_number.present? && account_number.match?(/\A[A-Za-z0-9]+\z/)
        raise Error.new("Invalid account number format: #{account_number}", :bad_request)
      end
    end

    attr_reader :username, :document, :password, :api_token

    def validate_configuration!
      return if @api_token.present?

      if @username.blank? || @document.blank? || @password.blank?
        raise ConfigurationError, "Either API token or all three username/document/password credentials are required"
      end
    end

    def token_auth?
      @api_token.present?
    end

    def with_retries(operation_name, max_retries: MAX_RETRIES)
      retries = 0

      begin
        yield
      rescue *RETRYABLE_ERRORS => e
        retries += 1

        if retries <= max_retries
          delay = calculate_retry_delay(retries)
          Rails.logger.warn(

View on GitHub (pinned to e69894adb9)

Solutions

  1. Preferred: create an API token in the Indexa Capital dashboard and configure only that — it replaces all three legacy fields
  2. Otherwise provide ALL three legacy fields: username (email), document (ID/NIF), and password
  3. Audit the stored Indexa credentials for the account and fill in whichever mode you choose completely
  4. Add paired validation in the settings UI (token XOR all-three) so partial saves are blocked with a clear message
  5. After fixing, test the connection with the provider's health/usage call before scheduling syncs

Example fix

# before: partial legacy credentials saved silently, provider blows up later
Provider::IndexaCapital.new(username: u, password: p)

# after: enforce a complete auth mode at the boundary
if api_token.blank? && [username, document, password].any?(&:blank?)
  raise ConfigurationError, "Provide either an API token, or username + document + password"
end
Provider::IndexaCapital.new(api_token:, username:, document:, password:)
Defensive patterns

Strategy: validation

Validate before calling

# Enforce a complete auth mode before building the provider
complete_token_mode  = api_token.present?
complete_legacy_mode = username.present? && document.present? && password.present?
unless complete_token_mode || complete_legacy_mode
  raise ArgumentError, "Indexa requires an API token, or username + document + password"
end

Type guard

def valid_indexa_auth?(api_token:, username:, document:, password:)
  api_token.present? || [username, document, password].all? { |c| c.present? }
end

Try / catch

begin
  provider = Provider::IndexaCapital.new(api_token:, username:, document:, password:)
  provider.validate_connection!
rescue Provider::IndexaCapital::ConfigurationError => e
  render_settings_error(message: e.message) # point user to token OR all-three fields
end

Prevention

When it happens

Trigger: Constructing the Indexa provider with only some legacy credentials (e.g. username + password but no document), only a document, or entirely blank credentials and no token. Raises during initialization/first use, before any HTTP request to the Indexa API.

Common situations: Users migrating from the legacy email/password login who leave out the document (NIF/ID) field, settings forms that save partially-filled credentials, importers that map only some fields, and new setups where the user skipped generating an API token in the Indexa dashboard.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/d99606061fccb46e. Report an issue: GitHub.