we-promise/sure · error · StandardError

SnapTrade is not authorized

Error message

SnapTrade is not authorized

What it means

Error "SnapTrade is not authorized" thrown in we-promise/sure.

Source

Thrown at app/models/snaptrade_item.rb:52

  scope :active, -> { where(scheduled_for_deletion: false) }
  # Syncable = active + authorized via OAuth (has an access token).
  # oauth_access_token is non-deterministically encrypted, so it can only be
  # queried with an IS NULL check (never persisted as "" -- see apply_oauth_tokens!).
  scope :syncable, -> { active.where.not(oauth_access_token: nil) }
  scope :ordered, -> { order(created_at: :desc) }
  scope :needs_update, -> { where(status: :requires_update) }

  def destroy_later
    update!(scheduled_for_deletion: true)
    DestroyJob.perform_later(self)
  end

  def import_latest_snaptrade_data(sync: nil)
    provider = snaptrade_provider
    unless provider
      Rails.logger.error "SnaptradeItem #{id} - Cannot import: OAuth not authorized"
      raise StandardError, "SnapTrade is not authorized"
    end

    SnaptradeItem::Importer.new(self, snaptrade_provider: provider, sync: sync).import
  rescue => e
    Rails.logger.error "SnaptradeItem #{id} - Failed to import data: #{e.message}"
    raise
  end

  def process_accounts
    return [] if snaptrade_accounts.empty?

    results = []
    # Process only accounts that are linked to a Sure account
    linked_snaptrade_accounts.includes(account_provider: :account).each do |snaptrade_account|
      account = snaptrade_account.current_account
      next unless account
      next if account.pending_deletion? || account.disabled?

View on GitHub (pinned to e69894adb9)

When it happens

Trigger: Thrown at app/models/snaptrade_item.rb:52 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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