we-promise/sure · error · Provider::AlphaVantage::Error

API error: #{parsed["Error Message"]}

Error message

API error: #{parsed["Error Message"]}

What it means

In the same check_api_error!, a present "Error Message" key in the response body raises Provider::AlphaVantage::Error with "API error: <message>". Alpha Vantage returns "Error Message" for invalid API calls: unknown/typo'd symbols, invalid function names, bad interval parameters, or malformed query strings. Unlike the "Note"/"Information" keys, this is a hard request failure, not a quota condition.

Source

Thrown at app/models/provider/alpha_vantage.rb:337

    # Alpha Vantage returns errors as JSON keys rather than HTTP status codes.
    def check_api_error!(parsed)
      return unless parsed.is_a?(Hash)

      # Rate limit: Alpha Vantage returns a "Note" key when rate-limited
      if parsed["Note"].present?
        Rails.logger.warn("AlphaVantage rate limit: #{parsed["Note"]}")
        raise RateLimitError, parsed["Note"]
      end

      # General info/limit messages
      if parsed["Information"].present?
        Rails.logger.warn("AlphaVantage info: #{parsed["Information"]}")
        raise RateLimitError, parsed["Information"]
      end

      # Explicit error messages for invalid parameters
      if parsed["Error Message"].present?
        raise Error, "API error: #{parsed["Error Message"]}"
      end
    end
end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Verify the symbol returns data on Alpha Vantage's own API demo page (or curl the endpoint with your key) and correct/normalize the symbol (e.g. dashes instead of dots for class shares).
  2. Check the function/interval parameters the provider sends for that call and confirm they are supported for the symbol's market.
  3. Rescue Provider::AlphaVantage::Error in the caller and surface a user-facing 'invalid symbol' message instead of a stack trace.
  4. If the symbol is valid via curl, confirm the app is sending the API key you think it is (not a demo key).

Example fix

# before
sync_security(symbol: "BRK.A") # => raises "API error: Invalid API call..."

# after
begin
  sync_security(symbol: normalized_symbol)
rescue Provider::AlphaVantage::Error => e
  Rails.logger.error("Alpha Vantage rejected symbol: #{e.message}")
  mark_security_as_unsupported # keep sync healthy, flag the row
end
Defensive patterns

Strategy: try-catch

Validate before calling

def valid_alpha_vantage_symbol?(symbol)
  symbol.is_a?(String) && symbol.match?(/\A[A-Z0-9.\-]{1,20}\z/) && !symbol.strip.empty?
end

Try / catch

begin
  provider.fetch(symbol)
rescue Provider::AlphaVantage::Error => e
  mark_security_unsupported(symbol, reason: e.message) # flag row, keep sync green
end

Prevention

When it happens

Trigger: Calling a price/quote endpoint with a nonexistent ticker symbol (e.g. "BRK.A" instead of "BRK-B"), an invalid interval, a delisted symbol, a wrong FUNCTION parameter, or a malformed query string. Any provider call whose parsed body contains "Error Message" triggers it before data extraction.

Common situations: User saves a ticker with an exchange-specific suffix Alpha Vantage does not accept; symbol was delisted/renamed; copy-paste whitespace in the symbol; provider switched endpoint naming; wrong API function name after a library update.

Related errors


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