datawhalechina/hello-agents · warning
获取提示失败
Error message
获取提示失败
What it means
Application guard for the hint call: 2xx + parsed JSON but result.success falsy; throws result.error or the '获取提示失败' fallback. Business-level rejection — typically no hints remaining or invalid session — rendered via alert('获取提示失败:'+message).
Source
Thrown at Co-creation-projects/afei-GuessWhoAmI/frontend/app.js:159
if (this.remainingHints <= 0) {
alert('提示次数已用完');
return;
}
this.setControlsDisabled(true);
try {
const response = await fetch('http://localhost:8000/api/game/hint', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({session_id: this.sessionId})
});
if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
const result = await response.json();
if (!result.success) throw new Error(result.error || '获取提示失败');
const data = result.data;
const hintText = data.hint || data.message || '暂无提示';
this.addMessage(`💡 提示:${hintText}`, 'agent');
this.remainingHints = data.remaining_hints !== undefined ?
data.remaining_hints :
this.remainingHints - 1;
this.updateStats();
} catch (error) {
alert(`获取提示失败:${error.message}`);
console.error('Hint error:', error);
} finally {
this.setControlsDisabled(false);
}
}
View on GitHub (pinned to 606a07d341)
Solutions
- Have the backend return a specific error code (e.g. NO_HINTS_LEFT) and show a friendly message instead of a generic alert
- Sync remaining_hints from the server on every chat/hint response (the code partially does this — ensure it also updates on denial)
- Log result to find the omitted reason; fix backend to always populate error
- Replace alert() with inline UI feedback
Defensive patterns
Strategy: validation
Validate before calling
if (this.remainingHints <= 0) { addMessage('没有剩余提示了', 'system'); return; } Try / catch
try { ... } catch (e) { alert(`获取提示失败:${e.message}`); } Prevention
- Trust server-side remaining_hints over client count
- Return machine-readable error codes from the backend
- Replace alert with inline non-blocking UI
When it happens
Trigger: Backend returns success:false when remaining_hints is 0, session unknown, or game over, and omits error. The client-side remainingHints counter can also drift from the server, so the user requests a hint the server already denies.
Common situations: Hint counter desync (client thinks hints remain, server says none); backend hint logic erroring but wrapped in success:false without error text.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/b4ddc99fcaef604c.
Report an issue: GitHub.