Skip to content

Commit 5dc719f

Browse files
authored
Update script.js
1 parent ac57611 commit 5dc719f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

script.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@ document.addEventListener("DOMContentLoaded", function () {
1414
try {
1515
const response = await fetch("https://chatproxy.azurewebsites.net/api/chatproxy", {
1616
method: "POST",
17-
headers: {
18-
"Content-Type": "application/json"
19-
},
17+
headers: { "Content-Type": "application/json" },
2018
body: JSON.stringify({ message: userMessage })
2119
});
2220

21+
const text = await response.text();
22+
2323
if (!response.ok) {
24-
throw new Error(`Serverfout: ${response.status}`);
24+
console.error("Foutstatus:", response.status, text);
25+
appendMessage("assistant", `⚠️ Serverfout (${response.status}): ${text}`);
26+
return;
27+
}
28+
29+
if (!text || text.trim() === "") {
30+
appendMessage("assistant", "⚠️ Geen antwoord ontvangen van de chatbot.");
31+
return;
2532
}
2633

27-
const text = await response.text();
2834
appendMessage("assistant", text);
2935
} catch (error) {
3036
console.error("Fout in fetch:", error);
31-
appendMessage("assistant", "⚠️ Er ging iets mis bij het ophalen van het antwoord.");
37+
appendMessage("assistant", "⚠️ Verbindingsfout of onbekende fout.");
3238
}
3339
});
3440

0 commit comments

Comments
 (0)