{"record":{"id":"229293bb753d1b95","repo":"we-promise/sure","slug":"mercury-provider-is-not-configured","errorCode":null,"errorMessage":"Mercury provider is not configured","messagePattern":"Mercury provider is not configured","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"app/models/mercury_item.rb","lineNumber":47,"sourceCode":"  scope :active, -> { where(scheduled_for_deletion: false) }\n  scope :syncable, -> { active }\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  # TODO: Implement data import from provider API\n  # This method should fetch the latest data from the provider and import it.\n  # May need provider-specific validation (e.g., session validity checks).\n  # See LunchflowItem#import_latest_lunchflow_data or EnableBankingItem#import_latest_enable_banking_data for examples.\n  def import_latest_mercury_data\n    provider = mercury_provider\n    unless provider\n      Rails.logger.error \"MercuryItem #{id} - Cannot import: provider is not configured\"\n      raise StandardError.new(\"Mercury provider is not configured\")\n    end\n\n    # TODO: Add any provider-specific validation here (e.g., session checks)\n    MercuryItem::Importer.new(self, mercury_provider: provider).import\n  rescue => e\n    Rails.logger.error \"MercuryItem #{id} - Failed to import data: #{e.message}\"\n    raise\n  end\n\n  # TODO: Implement account processing logic\n  # This method processes linked accounts after data import.\n  # Customize based on your provider's data structure and processing needs.\n  def process_accounts\n    return [] if mercury_accounts.empty?\n\n    results = []\n    mercury_accounts.joins(:account).merge(Account.visible).each do |mercury_account|\n      begin","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/mercury_item.rb#L29-L65","documentation":"AuthenticationError raised inside request_cookie_and_crumb when the GET to https://fc.yahoo.com returns a response whose Set-Cookie cannot be extracted (extract_cookie returns blank). fc.yahoo.com is the canonical trick to obtain the session cookie; if Yahoo returns an error page, a redirect without cookies, or a consent wall, there is no cookie to authorize the subsequent getcrumb call, so auth cannot proceed. The 429 case is converted to RateLimitError before this check.","triggerScenarios":"fc.yahoo.com responding 404/redirect without Set-Cookie (Yahoo has changed this behavior before); an intermediary proxy stripping Set-Cookie headers; Yahoo serving a consent/CAPTCHA page to your IP; cookie name changes making extract_cookie's parsing return nil.","commonSituations":"Datacenter IPs flagged by Yahoo; corporate proxies rewriting responses; Yahoo A/B changes to the cookie flow; Faraday middleware (e.g., aggressive cookie jar or redirect follower) consuming headers before extraction.","solutions":["Inspect the fc.yahoo.com response status and headers from the same host: curl -vI https://fc.yahoo.com | grep -i set-cookie","If 429s precede it, wait — rate limiting often degrades into cookie-less responses","Disable/adjust proxy or middleware that strips Set-Cookie","Retry later; transient Yahoo cookie-flow failures usually clear","If permanent, switch securities lookups to an alternative configured provider"],"exampleFix":"# before\ncookie = extract_cookie(cookie_response)\nraise AuthenticationError, \"Failed to obtain Yahoo Finance cookie\" if cookie.blank?\n\n# after (diagnose before failing)\ncookie = extract_cookie(cookie_response)\nif cookie.blank?\n  Rails.logger.error(\"fc.yahoo.com status=#{cookie_response.status} headers=#{cookie_response.headers['Set-Cookie'].inspect}\")\n  raise AuthenticationError, \"Failed to obtain Yahoo Finance cookie\"\nend","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"tries = 0\nbegin\n  tries += 1\n  provider.fetch_security_prices(symbol: s, start_date: a, end_date: b)\nrescue Provider::YahooFinance::AuthenticationError => e\n  raise unless e.message.include?(\"cookie\") && tries < 3\n  sleep(60)\n  retry\nend","preventionTips":["Rate-limit cookie bootstraps — repeated fc.yahoo.com hits from flagged IPs yield cookie-less responses","Avoid proxies/middleware that strip Set-Cookie","Cache the cookie/crumb pair for its extracted max-age instead of refetching per call","Monitor for Yahoo cookie-flow changes (they have historically altered fc.yahoo.com behavior)"],"tags":["yahoo-finance","authentication","cookie","set-cookie","anti-bot"],"backgroundTag":"api-authentication-failed","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}