geethareddy commited on
Commit
9ddd95d
·
verified ·
1 Parent(s): 3dad656

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +7 -2
static/script.js CHANGED
@@ -154,10 +154,15 @@ function getFoodSuggestions() {
154
  },
155
  body: JSON.stringify({ ingredients: selectedIngredients })
156
  })
157
- .then(response => response.json())
 
 
 
 
 
158
  .then(data => {
159
  if (data.error) {
160
- addMessage('bot', `Sorry, there was an error getting recipe ideas: ${data.error}. Please check your OpenAI quota or contact support.`);
161
  } else {
162
  addMessage('bot', 'Here are some recipe ideas based on your selected ingredients:');
163
  data.suggestions.forEach(suggestion => addMessage('bot', suggestion));
 
154
  },
155
  body: JSON.stringify({ ingredients: selectedIngredients })
156
  })
157
+ .then(response => {
158
+ if (!response.ok) {
159
+ throw new Error(`HTTP error! Status: ${response.status}`);
160
+ }
161
+ return response.json();
162
+ })
163
  .then(data => {
164
  if (data.error) {
165
+ addMessage('bot', data.error);
166
  } else {
167
  addMessage('bot', 'Here are some recipe ideas based on your selected ingredients:');
168
  data.suggestions.forEach(suggestion => addMessage('bot', suggestion));