How to trigger build fail
I am having an issue where a build completes successfully even when vital data is missing and makes the site unnavigable.
How do I trigger a build fail if fetch does not return a valid response?
Here is my Async Function:
async fetch() {
// Fetch the GlobalSettings object from Contentful,
// and if found bind it to a data prop
try {
const settingsPromise = this.$nacelle.client
.query({
query: ALLCONTENT,
variables: {
filter: {
handles: ['global-settings'],
type: 'globalSettings'
}
}
})
.then((res) => {
return res.data.allContent.edges[0].node
})
const menusPromise = this.$nacelle.client
.query({
query: ALLCONTENT,
variables: {
filter: {
type: 'menu',
first: 500
}
}
})
.then((res) => {
return res.data.allContent.edges.map((edge) => edge.node)
})
const [{ fields }, menus] = await Promise.all([
settingsPromise,
menusPromise
])
this.$store.commit('space/setMenus', menus)
const swatches = this.createColorCategories(fields?.colorSwatches)
this.initializeGlobalSettings(fields)
this.initializeColorCategories(swatches)
this.initCartMotivator()
} catch (e) {
console.warn(
No Global Settings entry found.
)
}
},1 Reply
The simple answer is make your build command return a non-success/0 exit code. How do you that in your build? Really depends what you're using to build and how it deals with errors.
#pages-help in the future btw