{"record":{"id":"636f3accee8c1a9e","repo":"we-promise/sure","slug":"snaptrade-is-not-authorized","errorCode":null,"errorMessage":"SnapTrade is not authorized","messagePattern":"SnapTrade is not authorized","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/snaptrade_item.rb","lineNumber":52,"sourceCode":"\n  scope :active, -> { where(scheduled_for_deletion: false) }\n  # Syncable = active + authorized via OAuth (has an access token).\n  # oauth_access_token is non-deterministically encrypted, so it can only be\n  # queried with an IS NULL check (never persisted as \"\" -- see apply_oauth_tokens!).\n  scope :syncable, -> { active.where.not(oauth_access_token: nil) }\n  scope :ordered, -> { order(created_at: :desc) }\n  scope :needs_update, -> { where(status: :requires_update) }\n\n  def destroy_later\n    update!(scheduled_for_deletion: true)\n    DestroyJob.perform_later(self)\n  end\n\n  def import_latest_snaptrade_data(sync: nil)\n    provider = snaptrade_provider\n    unless provider\n      Rails.logger.error \"SnaptradeItem #{id} - Cannot import: OAuth not authorized\"\n      raise StandardError, \"SnapTrade is not authorized\"\n    end\n\n    SnaptradeItem::Importer.new(self, snaptrade_provider: provider, sync: sync).import\n  rescue => e\n    Rails.logger.error \"SnaptradeItem #{id} - Failed to import data: #{e.message}\"\n    raise\n  end\n\n  def process_accounts\n    return [] if snaptrade_accounts.empty?\n\n    results = []\n    # Process only accounts that are linked to a Sure account\n    linked_snaptrade_accounts.includes(account_provider: :account).each do |snaptrade_account|\n      account = snaptrade_account.current_account\n      next unless account\n      next if account.pending_deletion? || account.disabled?\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/snaptrade_item.rb#L34-L70","documentation":"Error \"SnapTrade is not authorized\" thrown in we-promise/sure.","triggerScenarios":"Thrown at app/models/snaptrade_item.rb:52 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}