refactor: minior improvements

- ensure message is a string
- use location.reload to support hash # and also explictly bypass cache
- added minor comments
This commit is contained in:
Pooya Parsa 2018-09-28 11:50:13 +03:30
parent c4cfd08185
commit daf90215b5

View File

@ -140,11 +140,16 @@ async function loadAsyncComponents (to, from, next) {
next()
} catch (err) {
err = err || {}
if (/^Loading chunk (\d)+ failed\./.test(err.message)) {
window.location.replace(location.href)
const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
const message = err.message || ''
// Handle chunk loading errors
// This may be due to a new deployment or a network problem
if (/^Loading chunk (\d)+ failed\./.test(message)) {
window.location.reload(true /* skip cache */)
}
const statusCode = (err.statusCode || err.status || (err.response && err.response.status) || 500)
this.error({ statusCode, message: err.message })
this.error({ statusCode, message })
this.$nuxt.$emit('routeChanged', to, from, err)
next(false)
}