Spaces:
Sleeping
Sleeping
Update src/App.jsx
Browse files- src/App.jsx +12 -3
src/App.jsx
CHANGED
|
@@ -57,14 +57,23 @@ function App() {
|
|
| 57 |
headers: { 'Content-Type': 'application/json' },
|
| 58 |
body: JSON.stringify({ user_message: userInput }),
|
| 59 |
});
|
| 60 |
-
console.log("response",response);
|
| 61 |
-
console.log("response.json()",response.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
if (!response.ok) {
|
| 63 |
throw new Error(`HTTP error! status: ${response.status}`);
|
| 64 |
}
|
| 65 |
|
| 66 |
const data = await response.json();
|
| 67 |
-
consoloe.log("data",data)
|
| 68 |
const botMessage = { type: 'bot', text: data.bot_response, ts: Date.now(), sessionId };
|
| 69 |
|
| 70 |
// Update the chat log with the bot's response
|
|
|
|
| 57 |
headers: { 'Content-Type': 'application/json' },
|
| 58 |
body: JSON.stringify({ user_message: userInput }),
|
| 59 |
});
|
| 60 |
+
//console.log("response",response);
|
| 61 |
+
//console.log("response.json()",response.json())
|
| 62 |
+
|
| 63 |
+
if (!response.ok) {
|
| 64 |
+
// Read raw text so HTML errors don’t crash JSON parsing
|
| 65 |
+
const text = await response.text();
|
| 66 |
+
throw new Error(`Backend ${response.status}: ${text}`);
|
| 67 |
+
} else {
|
| 68 |
+
data = await response.json(); // safe now
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
if (!response.ok) {
|
| 72 |
throw new Error(`HTTP error! status: ${response.status}`);
|
| 73 |
}
|
| 74 |
|
| 75 |
const data = await response.json();
|
| 76 |
+
//consoloe.log("data",data)
|
| 77 |
const botMessage = { type: 'bot', text: data.bot_response, ts: Date.now(), sessionId };
|
| 78 |
|
| 79 |
// Update the chat log with the bot's response
|