Improve error handling in page components

This commit is contained in:
Sébastien Chopin 2017-01-20 18:11:30 +01:00
parent e6c3ef11be
commit 224a18dea8
2 changed files with 5 additions and 2 deletions

View File

@ -48,7 +48,8 @@ function loadAsyncComponents (to, ___, next) {
Promise.all(resolveComponents)
.then(() => next())
.catch((err) => {
this.error({ statusCode: 500, message: err.message })
let statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500
this.error({ statusCode, message: err.message })
next(false)
})
}
@ -148,6 +149,7 @@ function render (to, from, next) {
})
.catch((error) => {
_lastPaths = []
error.statusCode = error.statusCode || error.status || (error.response && error.response.status) || 500
this.error(error)
next(false)
})

View File

@ -130,7 +130,8 @@ export default context => {
})
.catch(function (error) {
if (error && (error instanceof Error || error.constructor.toString().indexOf('Error()') !== -1)) {
error = { statusCode: 500, message: error.message }
let statusCode = error.statusCode || error.status || (error.response && error.response.status) || 500
error = { statusCode, message: error.message }
}
else if (typeof error === 'string') {
error = { statusCode: 500, message: error }