Skip to content

Commit d6284df

Browse files
committed
handle response when no api key added telerik/kendo#23850
1 parent bd040f7 commit d6284df

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

Telerik.Examples.Mvc/NuGet.config

Lines changed: 0 additions & 9 deletions
This file was deleted.

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Telerik.Examples.Mvc.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2525
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
2626
<PackageReference Include="Telerik.Core.Export" Version="2025.3.812" />
27-
<PackageReference Include="Telerik.UI.for.AspNet.Core" Version="2025.3.825" />
27+
<PackageReference Include="Telerik.UI.for.AspNet.Core" Version="2025.4.1111" />
2828
<PackageReference Include="Telerik.Web.Captcha" Version="2.0.3" />
2929
<PackageReference Include="Telerik.Web.Spreadsheet" Version="2025.3.812" />
3030
</ItemGroup>

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Chat/ChatAiIntegration.cshtml

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,47 @@
1212

1313
<script>
1414
async function onSendMessage(e) {
15-
1615
e.message.authorName = "John Smith";
1716
const chat = $("#aiChat").data("kendoChat");
18-
const response = await fetch('/ChatAiIntegration/Ask', {
19-
method: 'POST',
20-
headers: { 'Content-Type': 'application/json' },
21-
body: JSON.stringify({ prompt: e.message.text })
22-
});
23-
const data = await response.json();
24-
25-
chat.postMessage({
26-
authorId: 'ai-assistant',
27-
authorName: 'AI Assistant',
28-
text: data.answer,
29-
id: kendo.guid(),
30-
timestamp: new Date()
31-
});
17+
18+
try {
19+
const response = await fetch('/ChatAiIntegration/Ask', {
20+
method: 'POST',
21+
headers: { 'Content-Type': 'application/json' },
22+
body: JSON.stringify({ prompt: e.message.text })
23+
});
24+
25+
if (!response.ok) {
26+
chat.postMessage({
27+
authorId: 'ai-assistant',
28+
authorName: 'AI Assistant',
29+
text: "Please add your Azure OpenAI keys in the AiService.cs file.",
30+
id: kendo.guid(),
31+
timestamp: new Date()
32+
});
33+
return;
34+
}
35+
36+
const data = await response.json();
37+
38+
chat.postMessage({
39+
authorId: 'ai-assistant',
40+
authorName: 'AI Assistant',
41+
text: data.answer,
42+
id: kendo.guid(),
43+
timestamp: new Date()
44+
});
45+
46+
} catch (error) {
47+
chat.postMessage({
48+
authorId: 'ai-assistant',
49+
authorName: 'AI Assistant',
50+
text: "The AI Service is currently unavailable. Please check your configuration.",
51+
id: kendo.guid(),
52+
timestamp: new Date()
53+
});
54+
}
3255
}
3356
</script>
3457

58+

0 commit comments

Comments
 (0)