mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
fix: async fetch and asyncData not trigger ErrorHandler (#3781)
This commit is contained in:
parent
b35126d68c
commit
3f7c5f64ed
@ -14,8 +14,7 @@ import {
|
||||
getLocation,
|
||||
compile,
|
||||
getQueryDiff,
|
||||
globalHandleError,
|
||||
empty
|
||||
globalHandleError
|
||||
} from './utils'
|
||||
|
||||
const noopData = () => { return {} }
|
||||
@ -35,7 +34,7 @@ Object.assign(Vue.config, <%= serialize(vue.config) %>)
|
||||
<% if (debug || mode === 'spa') { %>
|
||||
// Setup global Vue error handler
|
||||
const defaultErrorHandler = Vue.config.errorHandler
|
||||
Vue.config.errorHandler = (err, vm, info) => {
|
||||
Vue.config.errorHandler = (err, vm, info, ...rest) => {
|
||||
const nuxtError = {
|
||||
statusCode: err.statusCode || err.name || 'Whoops!',
|
||||
message: err.message || err.toString()
|
||||
@ -44,7 +43,7 @@ Vue.config.errorHandler = (err, vm, info) => {
|
||||
// Call other handler if exist
|
||||
let handled = null
|
||||
if (typeof defaultErrorHandler === 'function') {
|
||||
handled = defaultErrorHandler(...arguments)
|
||||
handled = defaultErrorHandler(err, vm, info, ...rest)
|
||||
}
|
||||
if (handled === true){
|
||||
return handled
|
||||
@ -347,8 +346,6 @@ async function render (to, from, next) {
|
||||
}
|
||||
<% } %>
|
||||
})
|
||||
// error will be handled in try catch
|
||||
.catch(empty)
|
||||
promises.push(promise)
|
||||
}
|
||||
|
||||
@ -368,8 +365,6 @@ async function render (to, from, next) {
|
||||
}
|
||||
<% } %>
|
||||
})
|
||||
// error will be handled in try catch
|
||||
.catch(empty)
|
||||
promises.push(p)
|
||||
}
|
||||
|
||||
|
9
test/fixtures/spa/pages/error-handler-async.vue
vendored
Normal file
9
test/fixtures/spa/pages/error-handler-async.vue
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
|
||||
export default {
|
||||
async asyncData() {
|
||||
await Promise.resolve()
|
||||
throw Error('asyncData error!')
|
||||
}
|
||||
}
|
||||
</script>
|
2
test/fixtures/spa/pages/error-handler.vue
vendored
2
test/fixtures/spa/pages/error-handler.vue
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
export default {
|
||||
fetch() {
|
||||
throw Error('spa test error!')
|
||||
throw Error('fetch error!')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
4
test/fixtures/spa/plugins/error.js
vendored
4
test/fixtures/spa/plugins/error.js
vendored
@ -1,5 +1,5 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
Vue.config.errorHandler = function () {
|
||||
document.body.appendChild(document.createTextNode('error handler triggered'))
|
||||
Vue.config.errorHandler = function (err) {
|
||||
document.body.appendChild(document.createTextNode(`error handler triggered: ${err.message}`))
|
||||
}
|
||||
|
@ -43,7 +43,13 @@ describe('spa', () => {
|
||||
test('/error-handler', async () => {
|
||||
await renderRoute('/error-handler')
|
||||
const { html } = await renderRoute('/error-handler')
|
||||
expect(html).toMatch('error handler triggered')
|
||||
expect(html).toMatch('error handler triggered: fetch error!')
|
||||
})
|
||||
|
||||
test('/error-handler-async', async () => {
|
||||
await renderRoute('/error-handler-async')
|
||||
const { html } = await renderRoute('/error-handler-async')
|
||||
expect(html).toMatch('error handler triggered: asyncData error!')
|
||||
})
|
||||
|
||||
test('/_nuxt/ (access publicPath in spa mode)', async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user