fix: add detailed error logging to voice agent for debugging
All checks were successful
Build & Push / build-and-push (push) Successful in 1m29s
All checks were successful
Build & Push / build-and-push (push) Successful in 1m29s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -243,7 +243,7 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
body: JSON.stringify({ locale }),
|
body: JSON.stringify({ locale }),
|
||||||
});
|
});
|
||||||
const tokenData = await tokenRes.json();
|
const tokenData = await tokenRes.json();
|
||||||
if (!tokenData.success) throw new Error('Token generation failed');
|
if (!tokenData.success) throw new Error(`Token generation failed: ${tokenData.error ?? tokenRes.status}`);
|
||||||
|
|
||||||
const { apiKey, model, config } = tokenData;
|
const { apiKey, model, config } = tokenData;
|
||||||
|
|
||||||
@@ -353,22 +353,26 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onerror = () => {
|
ws.onerror = (e) => {
|
||||||
|
console.error('[VoiceAgent] WebSocket error:', e);
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
setErrorMessage('Connection error. Please try again.');
|
setErrorMessage('Connection error. Please try again.');
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = (e) => {
|
||||||
|
console.log('[VoiceAgent] WebSocket closed:', e.code, e.reason);
|
||||||
if (status === 'active') {
|
if (status === 'active') {
|
||||||
setStatus('idle');
|
setStatus('idle');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('[VoiceAgent] Start failed:', error);
|
||||||
setStatus('error');
|
setStatus('error');
|
||||||
if (error instanceof DOMException && error.name === 'NotAllowedError') {
|
if (error instanceof DOMException && error.name === 'NotAllowedError') {
|
||||||
setErrorMessage('Microphone access was denied.');
|
setErrorMessage('Microphone access was denied.');
|
||||||
} else {
|
} else {
|
||||||
setErrorMessage('Failed to start conversation. Please try again.');
|
const msg = error instanceof Error ? error.message : 'Unknown error';
|
||||||
|
setErrorMessage(`Failed to start: ${msg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [locale, trackAmplitude, handleToolCall, playAudioChunk, addTranscript, status]);
|
}, [locale, trackAmplitude, handleToolCall, playAudioChunk, addTranscript, status]);
|
||||||
|
|||||||
Reference in New Issue
Block a user