Skip to content

Commit a244804

Browse files
authored
Merge pull request #109 from codex-team/for-nuxt
chore(vue): option to disable vue error handler
2 parents ef1c37a + 2f50f1e commit a244804

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Initialization settings:
7272
| `context` | object | optional | Any data you want to pass with every message. Has limitation of length. |
7373
| `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) |
7474
| `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling |
75+
| `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling |
7576
| `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |
7677

7778
Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition.

example/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ <h2>Test Vue integration: &lt;test-component&gt;</h2>
228228
<script>
229229
window.hawk = new HawkCatcher({
230230
token: 'eyJpbnRlZ3JhdGlvbklkIjoiNWU5OTE1MzItZTdiYy00ZjA0LTliY2UtYmIzZmE5ZTUwMTg3Iiwic2VjcmV0IjoiMTBlMTA4MjQtZTcyNC00YWFkLTkwMDQtMzExYTU1OWMzZTIxIn0=',
231-
collectorEndpoint: 'ws://localhost:3000/ws',
231+
// collectorEndpoint: 'ws://localhost:3000/ws',
232232
vue: window.Vue,
233233
context: {
234234
rootContextSample: '12345'
235-
}
235+
},
236236
})
237237
</script>
238238
</body>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hawk.so/javascript",
3-
"version": "3.0.8",
3+
"version": "3.0.9",
44
"description": "JavaScript errors tracking for Hawk.so",
55
"main": "./dist/hawk.js",
66
"types": "./dist/index.d.ts",

src/catcher.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export default class Catcher {
8181
*/
8282
private readonly stackParser: StackParser = new StackParser();
8383

84+
/**
85+
* Disable Vue.js error handler
86+
*/
87+
private readonly disableVueErrorHandler: boolean = false;
88+
8489
/**
8590
* Catcher constructor
8691
*
@@ -99,6 +104,7 @@ export default class Catcher {
99104
this.user = settings.user || Catcher.getGeneratedUser();
100105
this.context = settings.context || undefined;
101106
this.beforeSend = settings.beforeSend;
107+
this.disableVueErrorHandler = settings.disableVueErrorHandler ?? false;
102108

103109
if (!this.token) {
104110
log(
@@ -188,6 +194,8 @@ export default class Catcher {
188194
this.formatAndSend(error, {
189195
vue: addons,
190196
});
197+
}, {
198+
disableVueErrorHandler: this.disableVueErrorHandler,
191199
});
192200
}
193201

src/integrations/vue.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import Sanitizer from './../modules/sanitizer';
22
import { VueIntegrationAddons } from '@hawk.so/types';
33

4+
interface VueIntegrationOptions {
5+
/**
6+
* Disable Vue.js error handler
7+
*
8+
* Used by @hawk.so/nuxt since Nuxt has own error hook.
9+
* Otherwise, Nuxt will show 500 error
10+
*/
11+
disableVueErrorHandler?: boolean;
12+
}
13+
414
/**
515
* Errors fired inside Vue components are not dispatched by global handlers.
616
* This integration allow us to set up own error handler
@@ -28,13 +38,16 @@ export class VueIntegration {
2838
*
2939
* @param vue - Vue app to handle
3040
* @param callback - callback that accepts new error
41+
* @param options - additional options
3142
*/
32-
constructor(vue, callback) {
43+
constructor(vue, callback, options: VueIntegrationOptions) {
3344
this.vue = vue;
3445
this.existedHandler = vue.config.errorHandler;
3546
this.callback = callback;
3647

37-
this.setupHandler();
48+
if (options.disableVueErrorHandler !== true) {
49+
this.setupHandler();
50+
}
3851
}
3952

4053
/**

src/types/hawk-initial-settings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ export interface HawkInitialSettings {
6565
* This Method allows you to filter any data you don't want sending to Hawk
6666
*/
6767
beforeSend?(event: HawkJavaScriptEvent): HawkJavaScriptEvent;
68+
69+
/**
70+
* Disable Vue.js error handler
71+
*
72+
* Used by @hawk.so/nuxt since Nuxt has own error hook.
73+
*/
74+
disableVueErrorHandler?: boolean;
6875
}

stats.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
Size: 7.44 KB with all dependencies, minified and gzipped
2+
Size: 7.5 KB with all dependencies, minified and gzipped
33

0 commit comments

Comments
 (0)