{"record":{"id":"4f8dd4a99d97a325","repo":"we-promise/sure","slug":"unknown","errorCode":"unknown","errorMessage":"Unexpected error: #{response.code} - #{response.body}","messagePattern":"Unexpected error: #(.+?) - #(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/models/provider/indexa_capital.rb","lineNumber":215,"sourceCode":"        rescue JSON::ParserError => e\n          raise Error.new(\"Invalid JSON in response: #{e.message}\", :bad_response)\n        end\n      when 400\n        Rails.logger.error \"IndexaCapital API: Bad request - #{response.body}\"\n        raise Error.new(\"Bad request: #{response.body}\", :bad_request)\n      when 401\n        raise AuthenticationError.new(\"Invalid credentials\", :unauthorized)\n      when 403\n        raise AuthenticationError.new(\"Access forbidden - check your permissions\", :access_forbidden)\n      when 404\n        raise Error.new(\"Resource not found\", :not_found)\n      when 429\n        raise Error.new(\"Rate limit exceeded. Please try again later.\", :rate_limited)\n      when 500..599\n        raise Error.new(\"IndexaCapital server error (#{response.code}). Please try again later.\", :server_error)\n      else\n        Rails.logger.error \"IndexaCapital API: Unexpected response - Code: #{response.code}, Body: #{response.body}\"\n        raise Error.new(\"Unexpected error: #{response.code} - #{response.body}\", :unknown)\n      end\n    end\n\n    # Extract accounts array from /users/me response\n    # API returns: { accounts: [{ account_number: \"ABC12345\", type: \"mutual\", status: \"active\", ... }] }\n    def extract_accounts(user_data)\n      accounts = user_data[:accounts] || []\n      accounts.map do |acct|\n        {\n          account_number: acct[:account_number],\n          name: account_display_name(acct),\n          type: acct[:type],\n          status: acct[:status],\n          currency: \"EUR\",\n          raw: acct\n        }.with_indifferent_access\n      end\n    end","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/indexa_capital.rb#L197-L233","documentation":"The else-branch of handle_response: any status outside 200/201/400/401/403/404/429/500-599 - e.g. 202/204-style 2xx the case statement forgot, 3xx redirects, or odd 4xx like 405/410/418. Logged with code and body, then raised as Error(:unknown) with both embedded in the message.","triggerScenarios":"Indexa introduces a 202 Accepted for async operations; an http->https or domain redirect (301/302) because of a BASE_URL change; a load balancer returning 507/418-style codes; anything unmapped after an API version bump.","commonSituations":"Undocumented status codes appearing after provider deploys, redirect chains from API domain migrations, gateway-specific codes between the client and the origin server.","solutions":["Grep logs for 'IndexaCapital API: Unexpected response - Code:' - the code and body are printed there before the raise","Parse the leading number out of e.message to classify: 3xx means wrong URL, 2xx means the case statement needs a new arm, other 4xx means a new error condition","Capture response details via DebugLogEntry and report to Indexa support if it persists","Extend the when-clauses in handle_response once the new status is understood"],"exampleFix":"# before\nrescue Provider::IndexaCapital::Error => e\n  rollbar.report(e) # all unknowns alert identically\n\n# after\nrescue Provider::IndexaCapital::Error => e\n  code = e.message[/\\AUnexpected error: (\\d{3})/, 1].to_i\n  if code.between?(300, 399)\n    Rails.logger.error(\"Indexa redirect - BASE_URL drift? #{e.message}\")\n  else\n    rollbar.report(e)\n  end\nend","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def indexa_unknown_status?(error)\n  error.is_a?(Provider::IndexaCapital::Error) && error.error_type == :unknown\nend\n\ndef indexa_unknown_code(error)\n  error.message[/\\AUnexpected error: (\\d{3})/, 1].to_i\nend","tryCatchPattern":"begin\n  provider.list_accounts\nrescue Provider::IndexaCapital::Error => e\n  raise unless e.error_type == :unknown\n  code = e.message[/\\AUnexpected error: (\\d{3})/, 1].to_i\n  Rails.logger.error(\"Indexa unmapped status #{code}: #{e.message}\")\n  DebugLogEntry.capture(category: :indexa, level: :error,\n    message: e.message, metadata: { status: code })\n  raise\nend","preventionTips":["Grep for 'Unexpected response - Code:' to find unmapped statuses early","Classify by code family: 3xx = URL drift, unmapped 2xx = new semantics, 4xx = new error condition","Add smoke tests hitting each endpoint so contract drift surfaces in CI, not production","Extend handle_response's case arms once a new status is understood instead of string-parsing in callers"],"tags":["indexa-capital","catch-all","unexpected-status","http-3xx","api-contract"],"backgroundTag":"unexpected-http-status-code","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}