Skip to content

Commit

Permalink
feat: rename catchError -> errorCaptured
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 6, 2017
1 parent 514b90b commit 6dac3db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/core/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export function handleError (err: Error, vm: any, info: string) {
if (vm) {
let cur = vm
while ((cur = cur.$parent)) {
if (cur.$options.catchError) {

This comment has been minimized.

Copy link
@dsonet

dsonet Oct 7, 2017

Contributor

errorCaptured looks like a boolean property. IMO the catchError is better than this one.

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Oct 7, 2017

Author Member

This is because all hooks are named in the same style. If you think about it, hooks like mounted also sounds like a boolean.

if (cur.$options.errorCaptured) {
try {
const propagate = cur.$options.catchError.call(cur, err, vm, info)
const propagate = cur.$options.errorCaptured.call(cur, err, vm, info)
if (!propagate) return
} catch (e) {
globalHandleError(e, cur, 'catchError')
globalHandleError(e, cur, 'errorCaptured hook')
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Vue from 'vue'

describe('Options catchError', () => {
describe('Options errorCaptured', () => {
let globalSpy

beforeEach(() => {
Expand All @@ -26,7 +26,7 @@ describe('Options catchError', () => {
}

new Vue({
catchError: spy,
errorCaptured: spy,
render: h => h(Child)
}).$mount()

Expand All @@ -49,7 +49,7 @@ describe('Options catchError', () => {
data: {
error: null
},
catchError (e, vm, info) {
errorCaptured (e, vm, info) {
expect(vm).toBe(child)
this.error = e.toString() + ' in ' + info
},
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Options catchError', () => {
}

new Vue({
catchError (err, vm, info) {
errorCaptured (err, vm, info) {
spy(err, vm, info)
return true
},
Expand All @@ -108,14 +108,14 @@ describe('Options catchError', () => {

let err2
const vm = new Vue({
catchError () {
errorCaptured () {
err2 = new Error('foo')
throw err2
},
render: h => h(Child, {})
}).$mount()

expect(globalSpy).toHaveBeenCalledWith(err, child, 'created hook')
expect(globalSpy).toHaveBeenCalledWith(err2, vm, 'catchError')
expect(globalSpy).toHaveBeenCalledWith(err2, vm, 'errorCaptured hook')
})
})

0 comments on commit 6dac3db

Please sign in to comment.