8000 feat: Add logErrors option to Vue integration · CPatchane/sentry-javascript@3c7df57 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 3c7df57

Browse files
committed
feat: Add logErrors option to Vue integration
1 parent df0576f commit 3c7df57

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Unreleased
44

5-
- None
5+
- [integrations] feat: Add logErrors option to Vue integration (#2182)
6+
- [browser] test: Complete rewrite of Browser Integration Tests (#2176)
67

78
## 5.5.0
89

packages/integrations/src/vue.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,22 @@ export class Vue implements Integration {
3333
*/
3434
private readonly _attachProps: boolean = true;
3535

36+
/**
37+
* When set to true, original Vue's `logError` will be called as well.
38+
* https://github.com/vuejs/vue/blob/c2b1cfe9ccd08835f2d99f6ce60f67b4de55187f/src/core/util/error.js#L38-L48
39+
*/
40+
private readonly _logErrors: boolean = false;
41+
3642
/**
3743
* @inheritDoc
3844
*/
39-
public constructor(options: { Vue?: any; attachProps?: boolean } = {}) {
45+
public constructor(options: { Vue?: any; attachProps?: boolean; logErrors?: boolean } = {}) {
4046
// tslint:disable-next-line: no-unsafe-any
4147
this._Vue = options.Vue || getGlobalObject<any>().Vue;
48+
49+
if (options.logErrors !== undefined) {
50+
this._logErrors = options.logErrors;
51+
}
4252
if (options.attachProps === false) {
4353
this._attachProps = false;
4454
}
@@ -99,6 +109,14 @@ export class Vue implements Integration {
99109
if (typeof oldOnError === 'function') {
100110
oldOnError.call(this._Vue, error, vm, info);
101111
}
112+
113+
if (this._logErrors) {
114+
if (process && process.env && process.env.NODE_ENV !== 'production') {
115+
this._Vue.util.warn(`Error in ${info}: "${error.toString()}"`, vm);
116+
}
117+
// tslint:disable-next-line:no-console
118+
console.error(error);
119+
}
102120
};
103121
}
104122
}

0 commit comments

Comments
 (0)
0