Skip to content

Commit

Permalink
bug: handle ai-service health check failures
Browse files Browse the repository at this point in the history
and hide product id
  • Loading branch information
pauldotyu committed Jun 28, 2023
1 parent 83dcc0d commit 585d22d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/store-admin/src/components/ProductForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
</ul>
</div>
<div class="product-form">
<div class="form-row">
<label for="product-id">ID</label>
<input id="product-id" placeholder="Product ID" v-model="product.id" />
</div>

<div class="form-row">
<label for="product-name">Name</label>
<input id="product-name" placeholder="Product Name" v-model="product.name" />
Expand All @@ -34,7 +29,8 @@
<label for="product-description">Description</label>
<textarea id="product-description" placeholder="Product Description" v-model="product.description" />
<button @click="generateDescription" class="ai-button">Ask OpenAI</button>
</div>
<input type="hidden" id="product-id" placeholder="Product ID" v-model="product.id" />
</div>

<div class="form-row">
<label for="product-image">Image</label>
Expand Down Expand Up @@ -71,9 +67,6 @@
const product = this.products.find(product => product.id == this.$route.params.id)
// copy the product details into the product object
this.product = Object.assign({}, product);
} else {
// disable the product id textbox
document.getElementById('product-id').disabled = true;
}
// if the AI service is not responding, hide the button
Expand Down
13 changes: 11 additions & 2 deletions src/store-admin/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@ module.exports = defineConfig({
// Get AI service health
devServer.app.get('/ai/health', (_, res) => {
fetch(`${AI_SERVICE_URL}health`)
.then(response => res.send(response.json()))
.catch(error => console.error(error));
.then(response => {
if (response.status === 200) {
res.send(response.json());
} else {
res.status(500).send('Health check failed');
}
})
.catch(error => {
console.error(error);
res.status(500).send('Health check failed');
});
})

// Generate product description
Expand Down

0 comments on commit 585d22d

Please sign in to comment.