{"record":{"id":"77c635408d2c5c24","repo":"we-promise/sure","slug":"not-found","errorCode":"not_found","errorMessage":"Brex resource not found","messagePattern":"Brex resource not found","errorType":"http","errorClass":"Provider::Brex::BrexError","httpStatus":404,"severity":"warning","filePath":"app/models/provider/brex.rb","lineNumber":221,"sourceCode":"\n    def handle_response(response, path:)\n      trace_id = brex_trace_id(response)\n\n      case response.code\n      when 200\n        parse_json(response.body)\n      when 400\n        Rails.logger.error \"Brex API: bad request for #{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Bad request to Brex API\", :bad_request, http_status: 400, trace_id: trace_id)\n      when 401\n        Rails.logger.warn \"Brex API: unauthorized for #{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Invalid Brex API token or account permissions\", :unauthorized, http_status: 401, trace_id: trace_id)\n      when 403\n        Rails.logger.warn \"Brex API: access forbidden for #{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Access forbidden - check Brex API token scopes\", :access_forbidden, http_status: 403, trace_id: trace_id)\n      when 404\n        Rails.logger.warn \"Brex API: resource not found for #{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Brex resource not found\", :not_found, http_status: 404, trace_id: trace_id)\n      when 429\n        Rails.logger.warn \"Brex API: rate limited for #{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Brex rate limit exceeded. Please try again later.\", :rate_limited, http_status: 429, trace_id: trace_id)\n      else\n        Rails.logger.error \"Brex API: unexpected response code=#{response.code} path=#{path} trace_id=#{trace_id}\"\n        raise BrexError.new(\"Failed to fetch data from Brex API: HTTP #{response.code}\", :fetch_failed, http_status: response.code, trace_id: trace_id)\n      end\n    end\n\n    def parse_json(body)\n      return {} if body.blank?\n\n      JSON.parse(body, symbolize_names: true)\n    end\n\n    def rfc3339_start_date(start_date)\n      time =\n        case start_date","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/provider/brex.rb#L203-L239","documentation":"Raised by Provider::Brex#handle_response on HTTP 404: the Brex resource referenced by the request does not exist. In practice this almost always means the account id passed to get_cash_transactions was deleted (or never existed) at Brex, since paths are built from ids returned earlier by get_accounts. http_status 404 and trace_id are attached.","triggerScenarios":"get_cash_transactions(account_id, ...) where the account was closed/deleted at Brex after the last account-list sync; a stale or wrong account id reaching the client; querying a staging resource that only exists in production.","commonSituations":"Users closing Brex accounts between syncs while the local Account record persists; holding ids from an old environment; manually entered ids.","solutions":["Re-run client.get_accounts and verify the account id still appears; if gone, mark the local account closed/inactive instead of retrying","Verify the id came from Brex's own accounts response (ids are Brex-generated, not user names)","Check environment consistency (staging ids against production base_url 404)","Keep the trace_id if you need to ask Brex support about a resource you believe should exist"],"exampleFix":"# before\ntransactions = client.get_cash_transactions(account.brex_account_id)\n\n# after\nbegin\n  transactions = client.get_cash_transactions(account.brex_account_id)\nrescue Provider::Brex::BrexError => e\n  raise unless e.error_type == :not_found\n  account.update!(status: \"closed\", active: false)\n  transactions = { transactions: [] }\nend","handlingStrategy":"fallback","validationCode":"def brex_account_still_listed?(client, account_id)\n  client.get_accounts[:accounts].any? { |a| a.with_indifferent_access[:id] == account_id }\nrescue Provider::Brex::BrexError\n  false\nend","typeGuard":"def brex_not_found?(error)\n  error.is_a?(Provider::Brex::BrexError) && error.error_type == :not_found\nend","tryCatchPattern":"begin\n  client.get_cash_transactions(account_id)\nrescue Provider::Brex::BrexError => e\n  raise unless e.error_type == :not_found\n  account.update!(status: \"closed\", active: false) # degrade gracefully, no retry\n  { transactions: [] }\nend","preventionTips":["Refresh the account list via get_accounts before syncing transactions for ids not verified recently","Only use account ids returned by Brex itself","Treat 404 as an expected lifecycle event (closed account), not an alert-worthy failure","Keep environment (staging vs prod) consistent for stored ids"],"tags":["brex","http-404","accounts","sync"],"backgroundTag":"http-404-not-found","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}