Let's boil it down to the minimum.
I have this little component here that fetches data from the server. The diference with this component and any other is that it has to do two AJAX calls. One after the other!
<template>
<div>Easy</div>
</template>
<script>
import axios from 'axios'
let firstFetch = () => {
return axios.get('/first')
}
let secondFetch = () => {
return axios.get('/second')
}
export default {
name: 'p-components-accordion-box',
methods: {
setActive(index) {
this.$emit('setActive', index)
}
},
asyncData({store, route, router}) {
return new Promise((resolve, reject) => {
firstFetch()
.then((result) => {
secondFetch()
.then((result) => {
resolve()
})
.catch((error) => {
throw { url: '/404' };
})
})
.catch((error) => {
throw { url: '/404' };
})
})
}
}
</script>
<style>
</style>
The thing is this works perfect is all requests work. But if something goes wrong and I do:
throw { url: '/404' };
It works perfect in the browser, meaning I go to '/404' but on NodeJS I keep getting this message.
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Has anybody done something similar?