we-promise/sure · error · Provider::Brex::BrexError

request_failed

request_failed

Error message

Exception during GET request: #{e.message}

What it means

StandardError raised by SnaptradeItem::Syncer#perform_sync when snaptrade_item.oauth_configured? is false (oauth_access_token blank, app/models/snaptrade_item.rb:185). The syncer checks authorization up-front before phase 1 (importing accounts), so the failure happens before any SnapTrade API traffic. It exists to fail the Sync early with an actionable cause instead of a deeper nil-provider error inside the importer.

Source

Thrown at app/models/provider/brex.rb:176

      records
    end

    def get_json(path, params: {})
      query = params.present? ? "?#{URI.encode_www_form(params)}" : ""
      request_path = "#{path}#{query}"

      response = self.class.get(
        "#{base_url}#{request_path}",
        headers: auth_headers
      )

      handle_response(response, path: path)
    rescue BrexError
      raise
    rescue SocketError, Net::OpenTimeout, Net::ReadTimeout => e
      Rails.logger.error "Brex API: GET #{path} failed: #{e.class}: #{e.message}"
      raise BrexError.new("Exception during GET request: #{e.message}", :request_failed)
    rescue JSON::ParserError => e
      Rails.logger.error "Brex API: invalid JSON for GET #{path}: #{e.message}"
      raise BrexError.new("Invalid response from Brex API", :invalid_response)
    rescue => e
      Rails.logger.error "Brex API: Unexpected error during GET #{path}: #{e.class}: #{e.message}"
      raise BrexError.new("Exception during GET request: #{e.message}", :request_failed)
    end

    def extract_records(response_payload)
      return response_payload if response_payload.is_a?(Array)

      payload = response_payload.with_indifferent_access
      payload[:items] ||
        payload[:data] ||
        payload[:accounts] ||
        payload[:transactions] ||
        []
    end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Reauthorize SnapTrade for the item (complete OAuth) then re-run the sync
  2. Before enqueueing, skip items where oauth_configured? is false
  3. Mark the Sync record failed with a clear status (e.g., 'SnapTrade not authorized') when rescuing in the job
  4. Cancel pending sync jobs when OAuth tokens are cleared or the item is scheduled for deletion

Example fix

# before
SnaptradeItem::Syncer.new(item).perform_sync(sync)

# after
unless item.oauth_configured?
  sync.update!(status: :error, status_text: "SnapTrade not authorized — reconnect required")
  next
end
SnaptradeItem::Syncer.new(item).perform_sync(sync)
Defensive patterns

Strategy: validation

Validate before calling

unless item.oauth_configured?
  sync.update!(status: :error, status_text: "SnapTrade not authorized — reconnect required")
  return
end

Try / catch

begin
  SnaptradeItem::Syncer.new(item).perform_sync(sync)
rescue StandardError => e
  raise unless e.message == "SnapTrade is not authorized"
  sync.update!(status: :error, status_text: "Reconnect SnapTrade to re-enable syncing")
end

Prevention

When it happens

Trigger: Sync job enqueued/running after the user revoked SnapTrade OAuth; item created but authorization abandoned mid-flow; tokens cleared by an admin; race between destroy_later and an in-flight scheduled sync.

Common situations: Scheduled nightly syncs for disconnected items; user disconnecting during an active sync; seeded/test environments with unauthorized items being synced by a shared scheduler.

Related errors


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