Why this matters
Avoids method errors on unexpected payloads and surfaces transport failures.
Validate HTTP status and safely access nested response data using `dig`/guards.
Avoids method errors on unexpected payloads and surfaces transport failures.
Side-by-side examples engineers can pattern-match during review.
json = JSON.parse(resp.body); token = json["data"]["token"]raise "HTTP #{resp.code}" unless resp.code.to_i < 400
json = JSON.parse(resp.body)
token = json.dig("data", "token")JSON.parse(resp.body)['x']['y']JSON.parse(resp.body).dig('x','y')From the same buckets as this rule.