-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(errors): propogate thrown errors by configuring error handler (#154
) * Propogate thrown errors by configuring error handler and attaching in mount function resolves #147 * set errorHandler to be a default export and set Vue.config.errorHandler = errorHandler in mount * Add test for create-local-vue error handler being defined and configure that in create local vue
- Loading branch information
1 parent
e484c7e
commit 3f3c64a
Showing
7 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function errorMessage (msg, info) { | ||
if (info) { | ||
return `${msg} : additional info ${info}` | ||
} | ||
|
||
return msg | ||
} | ||
|
||
export default function errorHandler (err, _vm, info) { | ||
if ((typeof err === 'object') && err.message) { | ||
if (info) { | ||
err.message = errorMessage(err.message, info) | ||
} | ||
|
||
throw err | ||
} | ||
|
||
throw new Error(errorMessage(err, info)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import errorHandler from '../../../../src/lib/error-handler' | ||
|
||
describe('errorHandler', () => { | ||
const errorString = 'errorString' | ||
const info = 'additional info provided by vue' | ||
const errorObject = new Error(errorString) | ||
|
||
it('when error object: rethrows error', () => { | ||
expect(() => errorHandler(errorObject)).to.throw().with.property('message', errorString) | ||
}) | ||
|
||
it('when error object: rethrown error contains vue info when provided', () => { | ||
expect(() => errorHandler(errorObject, {}, info)).to.throw().that.satisfies(function (err) { | ||
const errorMessage = err.message | ||
|
||
return errorMessage.includes(errorString) && errorMessage.includes(info) | ||
}) | ||
}) | ||
|
||
it('when error string: throws error with string', () => { | ||
expect(() => errorHandler(errorString)).to.throw().with.property('message', errorString) | ||
}) | ||
|
||
it('throws error with string and appends info when provided', () => { | ||
expect(() => errorHandler(errorString, {}, info)).to.throw().that.satisfies(function (err) { | ||
const errorMessage = err.message | ||
|
||
return errorMessage.includes(errorString) && errorMessage.includes(info) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters