From daf90215b5ab27c99140cbf7f69dad0d82733ebe Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Fri, 28 Sep 2018 11:50:13 +0330 Subject: [PATCH] refactor: minior improvements - ensure message is a string - use location.reload to support hash # and also explictly bypass cache - added minor comments --- lib/app/client.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index 869eb3e87..0d120242f 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -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) }