{"record":{"id":"0410b43b973f0cca","repo":"we-promise/sure","slug":"request-failed","errorCode":"request_failed","errorMessage":"Exception during GET request: #{e.message}","messagePattern":"Exception during GET request: #(.+?)","errorType":"exception","errorClass":"Provider::Brex::BrexError","httpStatus":null,"severity":"error","filePath":"app/models/provider/brex.rb","lineNumber":176,"sourceCode":"\n      records\n    end\n\n    def get_json(path, params: {})\n      query = params.present? ? \"?#{URI.encode_www_form(params)}\" : \"\"\n      request_path = \"#{path}#{query}\"\n\n      response = self.class.get(\n        \"#{base_url}#{request_path}\",\n        headers: auth_headers\n      )\n\n      handle_response(response, path: path)\n    rescue BrexError\n      raise\n    rescue SocketError, Net::OpenTimeout, Net::ReadTimeout => e\n      Rails.logger.error \"Brex API: GET #{path} failed: #{e.class}: #{e.message}\"\n      raise BrexError.new(\"Exception during GET request: #{e.message}\", :request_failed)\n    rescue JSON::ParserError => e\n      Rails.logger.error \"Brex API: invalid JSON for GET #{path}: #{e.message}\"\n      raise BrexError.new(\"Invalid response from Brex API\", :invalid_response)\n    rescue => e\n      Rails.logger.error \"Brex API: Unexpected error during GET #{path}: #{e.class}: #{e.message}\"\n      raise BrexError.new(\"Exception during GET request: #{e.message}\", :request_failed)\n    end\n\n    def extract_records(response_payload)\n      return response_payload if response_payload.is_a?(Array)\n\n      payload = response_payload.with_indifferent_access\n      payload[:items] ||\n        payload[:data] ||\n        payload[:accounts] ||\n        payload[:transactions] ||\n        []\n    end","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/brex.rb#L158-L194","documentation":"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.","triggerScenarios":"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.","commonSituations":"Scheduled nightly syncs for disconnected items; user disconnecting during an active sync; seeded/test environments with unauthorized items being synced by a shared scheduler.","solutions":["Reauthorize SnapTrade for the item (complete OAuth) then re-run the sync","Before enqueueing, skip items where oauth_configured? is false","Mark the Sync record failed with a clear status (e.g., 'SnapTrade not authorized') when rescuing in the job","Cancel pending sync jobs when OAuth tokens are cleared or the item is scheduled for deletion"],"exampleFix":"# before\nSnaptradeItem::Syncer.new(item).perform_sync(sync)\n\n# after\nunless item.oauth_configured?\n  sync.update!(status: :error, status_text: \"SnapTrade not authorized — reconnect required\")\n  next\nend\nSnaptradeItem::Syncer.new(item).perform_sync(sync)","handlingStrategy":"validation","validationCode":"unless item.oauth_configured?\n  sync.update!(status: :error, status_text: \"SnapTrade not authorized — reconnect required\")\n  return\nend","typeGuard":null,"tryCatchPattern":"begin\n  SnaptradeItem::Syncer.new(item).perform_sync(sync)\nrescue StandardError => e\n  raise unless e.message == \"SnapTrade is not authorized\"\n  sync.update!(status: :error, status_text: \"Reconnect SnapTrade to re-enable syncing\")\nend","preventionTips":["Skip enqueueing SnaptradeItem::Syncer jobs for items lacking oauth_access_token","Re-check authorization at job runtime (tokens can be revoked after enqueue)","Clean up scheduled syncs when items are marked scheduled_for_deletion"],"tags":["snaptrade","oauth","provider-not-configured","sync-job","authorization"],"backgroundTag":"provider-not-configured","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}