|
| 1 | +/* global bugsnag, Vue, bugsnag__vue */ |
| 2 | + |
1 | 3 | // www.bugsnag.com |
2 | 4 | // https://github.com/bugsnag/bugsnag-vue/tree/master/example |
3 | 5 | // |
|
9 | 11 | // Initialize Bugsnag to begin tracking errors. Only an api key is required, but here are some other helpful configuration details: |
10 | 12 | const bugsnagClient = bugsnag({ |
11 | 13 |
|
12 | | - // get your own api key at bugsnag.com |
13 | | - apiKey: 'API_KEY', |
| 14 | + // get your own api key at bugsnag.com |
| 15 | + apiKey: 'API_KEY', |
14 | 16 |
|
15 | | - // if you track deploys or use source maps, make sure to set the correct version. |
16 | | - appVersion: '1.2.3', |
| 17 | + // if you track deploys or use source maps, make sure to set the correct version. |
| 18 | + appVersion: '1.2.3', |
17 | 19 |
|
18 | | - // Bugsnag can track the number of “sessions” that happen in your application, and calculate a crash rate for each release. This defaults to false. |
19 | | - autoCaptureSessions: true, |
| 20 | + // Bugsnag can track the number of “sessions” that happen in your application, and calculate a crash rate for each release. This defaults to false. |
| 21 | + autoCaptureSessions: true, |
20 | 22 |
|
21 | | - // defines the release stage for all events that occur in this app. |
22 | | - releaseStage: 'development', |
| 23 | + // defines the release stage for all events that occur in this app. |
| 24 | + releaseStage: 'development', |
23 | 25 |
|
24 | | - // defines which release stages bugsnag should report. e.g. ignore staging errors. |
25 | | - notifyReleaseStages: [ 'development', 'production'], |
| 26 | + // defines which release stages bugsnag should report. e.g. ignore staging errors. |
| 27 | + notifyReleaseStages: [ 'development', 'production' ], |
26 | 28 |
|
27 | | - // one of the most powerful tools in our library, beforeSend lets you evaluate, modify, add and remove data before sending the error to bugsnag. The actions here will be applied to *all* errors, handled and unhandled. |
28 | | - beforeSend: function (report) { |
29 | | - if (report.errorClass === 'Error' && report.severity === 'warning') { |
30 | | - report.updateMetaData('example', {thing: "one"}) |
31 | | - } |
| 29 | + // one of the most powerful tools in our library, beforeSend lets you evaluate, modify, add and remove data before sending the error to bugsnag. The actions here will be applied to *all* errors, handled and unhandled. |
| 30 | + beforeSend: function (report) { |
| 31 | + if (report.errorClass === 'Error' && report.severity === 'warning') { |
| 32 | + report.updateMetaData('example', { thing: 'one' }) |
| 33 | + } |
32 | 34 | // note that if you return false from the beforeSend, this will cancel the entire error report. |
33 | | - }, |
| 35 | + }, |
34 | 36 |
|
35 | | - // attached any user data you'd like to report. |
36 | | - user: { |
37 | | - name: "Katherine Johnson", |
38 | | - email: "kj@nasa.gov", |
39 | | - id: "0112358" |
40 | | - }, |
| 37 | + // attached any user data you'd like to report. |
| 38 | + user: { |
| 39 | + name: 'Katherine Johnson', |
| 40 | + email: 'kj@nasa.gov', |
| 41 | + id: '0112358' |
| 42 | + }, |
41 | 43 |
|
42 | | - // add any custom attributes relevant to your app. Note that metadata can be added here, in a specific notify() or in a beforeSend. |
43 | | - metaData: { company: { |
44 | | - name: "Hogwarts School of Witchcraft and Wizardry" |
45 | | - } |
46 | | - }, |
47 | | - // N.B. our notifer automatically creates a metadata tab called "React" and populates it with component info. |
| 44 | + // add any custom attributes relevant to your app. Note that metadata can be added here, in a specific notify() or in a beforeSend. |
| 45 | + metaData: { |
| 46 | + company: { |
| 47 | + name: 'Hogwarts School of Witchcraft and Wizardry' |
| 48 | + } |
| 49 | + }, |
| 50 | + // N.B. our notifer automatically creates a metadata tab called "Vue" and populates it with component info. |
48 | 51 |
|
49 | | - // because this is a demo app, below extends the default of 10 notifications per pageload. click away! |
50 | | - maxEvents: 50 |
| 52 | + // because this is a demo app, below extends the default of 10 notifications per pageload. click away! |
| 53 | + maxEvents: 50 |
51 | 54 | }) |
52 | 55 |
|
53 | 56 | // attach the Vue plugin to your bugsnag-js client |
54 | 57 | bugsnagClient.use(bugsnag__vue(Vue)) |
55 | 58 |
|
56 | | - |
57 | 59 | // Define the <bad-button/> component |
58 | 60 | Vue.component('bad-button', { |
59 | 61 | template: '#bad-button-template', |
@@ -85,14 +87,14 @@ var app = new Vue({ |
85 | 87 | if (val) { |
86 | 88 | try { |
87 | 89 | // potentially buggy code goes here |
88 | | - //for this example, we're just throwing an error explicitly, but you do not need this syntax in your try clause. |
| 90 | + // for this example, we're just throwing an error explicitly, but you do not need this syntax in your try clause. |
89 | 91 | throw new Error('Bad thing!') |
90 | 92 | } catch (e) { |
91 | 93 | console.log('a handled error has been reported to your Bugsnag dashboard') |
92 | 94 | // below modifies the handled error, and then sends it to your dashboard. |
93 | 95 | bugsnagClient.notify(e, { |
94 | 96 | context: 'Don\'t worry - I handled it.' |
95 | | - }); |
| 97 | + }) |
96 | 98 | } |
97 | 99 | } |
98 | 100 | } |
@@ -126,7 +128,6 @@ var app = new Vue({ |
126 | 128 | } |
127 | 129 | }) |
128 | 130 |
|
129 | | - |
130 | 131 | // below is the simplest notification syntax, akin to logging. |
131 | 132 | console.log('a notification has been reported to your Bugsnag dashboard') |
132 | 133 | bugsnagClient.notify('End of file') |
0 commit comments