Skip to content

Commit

Permalink
Merge pull request #109 from codex-team/for-nuxt
Browse files Browse the repository at this point in the history
chore(vue): option to disable vue error handler
  • Loading branch information
neSpecc authored Oct 16, 2024
2 parents ef1c37a + 2f50f1e commit a244804
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Initialization settings:
| `context` | object | optional | Any data you want to pass with every message. Has limitation of length. |
| `vue` | Vue constructor | optional | Pass Vue constructor to set up the [Vue integration](#integrate-to-vue-application) |
| `disableGlobalErrorsHandling` | boolean | optional | Do not initialize global errors handling |
| `disableVueErrorHandler` | boolean | optional | Do not initialize Vue errors handling |
| `beforeSend` | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |

Other available [initial settings](types/hawk-initial-settings.d.ts) are described at the type definition.
Expand Down
4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ <h2>Test Vue integration: &lt;test-component&gt;</h2>
<script>
window.hawk = new HawkCatcher({
token: 'eyJpbnRlZ3JhdGlvbklkIjoiNWU5OTE1MzItZTdiYy00ZjA0LTliY2UtYmIzZmE5ZTUwMTg3Iiwic2VjcmV0IjoiMTBlMTA4MjQtZTcyNC00YWFkLTkwMDQtMzExYTU1OWMzZTIxIn0=',
collectorEndpoint: 'ws://localhost:3000/ws',
// collectorEndpoint: 'ws://localhost:3000/ws',
vue: window.Vue,
context: {
rootContextSample: '12345'
}
},
})
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hawk.so/javascript",
"version": "3.0.8",
"version": "3.0.9",
"description": "JavaScript errors tracking for Hawk.so",
"main": "./dist/hawk.js",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/catcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export default class Catcher {
*/
private readonly stackParser: StackParser = new StackParser();

/**
* Disable Vue.js error handler
*/
private readonly disableVueErrorHandler: boolean = false;

/**
* Catcher constructor
*
Expand All @@ -99,6 +104,7 @@ export default class Catcher {
this.user = settings.user || Catcher.getGeneratedUser();
this.context = settings.context || undefined;
this.beforeSend = settings.beforeSend;
this.disableVueErrorHandler = settings.disableVueErrorHandler ?? false;

if (!this.token) {
log(
Expand Down Expand Up @@ -188,6 +194,8 @@ export default class Catcher {
this.formatAndSend(error, {
vue: addons,
});
}, {
disableVueErrorHandler: this.disableVueErrorHandler,
});
}

Expand Down
17 changes: 15 additions & 2 deletions src/integrations/vue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import Sanitizer from './../modules/sanitizer';
import { VueIntegrationAddons } from '@hawk.so/types';

interface VueIntegrationOptions {
/**
* Disable Vue.js error handler
*
* Used by @hawk.so/nuxt since Nuxt has own error hook.
* Otherwise, Nuxt will show 500 error
*/
disableVueErrorHandler?: boolean;
}

/**
* Errors fired inside Vue components are not dispatched by global handlers.
* This integration allow us to set up own error handler
Expand Down Expand Up @@ -28,13 +38,16 @@ export class VueIntegration {
*
* @param vue - Vue app to handle
* @param callback - callback that accepts new error
* @param options - additional options
*/
constructor(vue, callback) {
constructor(vue, callback, options: VueIntegrationOptions) {

Check warning on line 43 in src/integrations/vue.ts

View workflow job for this annotation

GitHub Actions / publish

Argument 'vue' should be typed

Check warning on line 43 in src/integrations/vue.ts

View workflow job for this annotation

GitHub Actions / publish

Argument 'callback' should be typed
this.vue = vue;
this.existedHandler = vue.config.errorHandler;
this.callback = callback;

this.setupHandler();
if (options.disableVueErrorHandler !== true) {
this.setupHandler();
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/types/hawk-initial-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,11 @@ export interface HawkInitialSettings {
* This Method allows you to filter any data you don't want sending to Hawk
*/
beforeSend?(event: HawkJavaScriptEvent): HawkJavaScriptEvent;

/**
* Disable Vue.js error handler
*
* Used by @hawk.so/nuxt since Nuxt has own error hook.
*/
disableVueErrorHandler?: boolean;
}
2 changes: 1 addition & 1 deletion stats.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

Size: 7.44 KB with all dependencies, minified and gzipped
Size: 7.5 KB with all dependencies, minified and gzipped

0 comments on commit a244804

Please sign in to comment.