Add null check for Z.ai API response choices#7
Conversation
Prevents crash when API returns empty or malformed choices array. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Z.ai Code ReviewHere is the review of the changes: 1. Security: Potential Data Leak in Error MessagesSeverity: Medium Recommendation: reject(new Error('Z.ai API returned an empty or unexpected response structure'));2. Logic: Distinguishing "Empty" from "Malformed"Severity: Low Recommendation: if (!parsed.choices || !parsed.choices.length) {
reject(new Error('Z.ai API response missing choices array'));
}
const content = parsed.choices[0].message?.content;
// ... proceed to check if content is empty string3. Behavior: Strict Empty String HandlingSeverity: Info 4. Robustness: JSON Parsing SafetySeverity: Minor Recommendation: |
Prevents crash when API returns empty or malformed choices array.