Skip to content

Commit c788bb0

Browse files
authored
Update script.js
1 parent aa545dd commit c788bb0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

script.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,25 @@ form.addEventListener("submit", async (e) => {
1111
input.value = "";
1212

1313
try {
14+
console.log("Verzend dit naar chatproxy:", message);
15+
1416
const response = await fetch("https://chatproxy.azurewebsites.net/api/chatproxy", {
1517
method: "POST",
1618
headers: { "Content-Type": "application/json" },
1719
body: JSON.stringify({ message })
1820
});
1921

20-
// LET OP: geen .json() gebruiken, want backend stuurt platte tekst terug
2122
const text = await response.text();
22-
appendMessage("Agent", text);
23+
console.log("Ontvangen van proxy:", text);
24+
25+
if (!response.ok) {
26+
throw new Error(`Serverfout: ${response.status}`);
27+
}
2328

29+
appendMessage("Agent", text);
2430
} catch (err) {
25-
appendMessage("Agent", "Er ging iets mis.");
26-
console.error(err);
31+
appendMessage("Agent", "Er ging iets mis bij het ophalen van het zorgdocument.");
32+
console.error("Fout in fetch:", err);
2733
}
2834
});
2935

@@ -33,4 +39,3 @@ function appendMessage(sender, text) {
3339
chat.appendChild(msg);
3440
chat.scrollTop = chat.scrollHeight;
3541
}
36-

0 commit comments

Comments
 (0)