we-promise/sure · error · Error

unknown

unknown

Error message

Unexpected error: #{response.code} - #{response.body}

What it means

The else-branch of handle_response: any status outside 200/201/400/401/403/404/429/500-599 - e.g. 202/204-style 2xx the case statement forgot, 3xx redirects, or odd 4xx like 405/410/418. Logged with code and body, then raised as Error(:unknown) with both embedded in the message.

Source

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

        rescue JSON::ParserError => e
          raise Error.new("Invalid JSON in response: #{e.message}", :bad_response)
        end
      when 400
        Rails.logger.error "IndexaCapital API: Bad request - #{response.body}"
        raise Error.new("Bad request: #{response.body}", :bad_request)
      when 401
        raise AuthenticationError.new("Invalid credentials", :unauthorized)
      when 403
        raise AuthenticationError.new("Access forbidden - check your permissions", :access_forbidden)
      when 404
        raise Error.new("Resource not found", :not_found)
      when 429
        raise Error.new("Rate limit exceeded. Please try again later.", :rate_limited)
      when 500..599
        raise Error.new("IndexaCapital server error (#{response.code}). Please try again later.", :server_error)
      else
        Rails.logger.error "IndexaCapital API: Unexpected response - Code: #{response.code}, Body: #{response.body}"
        raise Error.new("Unexpected error: #{response.code} - #{response.body}", :unknown)
      end
    end

    # Extract accounts array from /users/me response
    # API returns: { accounts: [{ account_number: "ABC12345", type: "mutual", status: "active", ... }] }
    def extract_accounts(user_data)
      accounts = user_data[:accounts] || []
      accounts.map do |acct|
        {
          account_number: acct[:account_number],
          name: account_display_name(acct),
          type: acct[:type],
          status: acct[:status],
          currency: "EUR",
          raw: acct
        }.with_indifferent_access
      end
    end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Grep logs for 'IndexaCapital API: Unexpected response - Code:' - the code and body are printed there before the raise
  2. Parse the leading number out of e.message to classify: 3xx means wrong URL, 2xx means the case statement needs a new arm, other 4xx means a new error condition
  3. Capture response details via DebugLogEntry and report to Indexa support if it persists
  4. Extend the when-clauses in handle_response once the new status is understood

Example fix

# before
rescue Provider::IndexaCapital::Error => e
  rollbar.report(e) # all unknowns alert identically

# after
rescue Provider::IndexaCapital::Error => e
  code = e.message[/\AUnexpected error: (\d{3})/, 1].to_i
  if code.between?(300, 399)
    Rails.logger.error("Indexa redirect - BASE_URL drift? #{e.message}")
  else
    rollbar.report(e)
  end
end
Defensive patterns

Strategy: try-catch

Type guard

def indexa_unknown_status?(error)
  error.is_a?(Provider::IndexaCapital::Error) && error.error_type == :unknown
end

def indexa_unknown_code(error)
  error.message[/\AUnexpected error: (\d{3})/, 1].to_i
end

Try / catch

begin
  provider.list_accounts
rescue Provider::IndexaCapital::Error => e
  raise unless e.error_type == :unknown
  code = e.message[/\AUnexpected error: (\d{3})/, 1].to_i
  Rails.logger.error("Indexa unmapped status #{code}: #{e.message}")
  DebugLogEntry.capture(category: :indexa, level: :error,
    message: e.message, metadata: { status: code })
  raise
end

Prevention

When it happens

Trigger: Indexa introduces a 202 Accepted for async operations; an http->https or domain redirect (301/302) because of a BASE_URL change; a load balancer returning 507/418-style codes; anything unmapped after an API version bump.

Common situations: Undocumented status codes appearing after provider deploys, redirect chains from API domain migrations, gateway-specific codes between the client and the origin server.

Related errors


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