エラーハンドリング
このトピックでは、Reveal SDK AI クライアントを使用する際のエラー処理方法について説明します。
エラーハンドリング
非ストリーミング
リクエストを try/catch ブロックで囲みます。
try {
const insight = await client.ai.insights.get({
dashboardId: 'sales-dashboard',
type: 'summary',
});
displayInsight(insight.explanation);
} catch (error) {
console.error('Request failed:', error);
showErrorMessage(error.message);
}
チャットにも同じパターンが適用されます。
try {
const response = await client.ai.chat.sendMessage({
message: 'Show me sales trends',
datasourceId: 'my-datasource',
});
displayResponse(response.explanation);
if (response.dashboard) {
loadDashboard(response.dashboard);
}
} catch (error) {
console.error('Chat request failed:', error);
showErrorMessage(error.message);
}