项目作者: anteriovieira

项目描述 :
vue-raven automatically reports uncaught JavaScript exceptions triggered from vue component
高级语言: JavaScript
项目地址: git://github.com/anteriovieira/vue-raven.git
创建时间: 2017-12-20T20:31:49Z
项目社区:https://github.com/anteriovieira/vue-raven

开源协议:MIT License

下载


VueRaven

npm (scoped with tag)
vue2
npm
CircleCI
Codecov
donate

VueRaven automatically reports uncaught JavaScript exceptions triggered from vue component, and provides a API for reporting your own errors. The captured errors will be reported to the sentry where you can get an overview of your application. If you do not already have a Sentry account, creating your account will be the first step to using this package.

Installation

  1. npm install --save vue-raven
  2. # or
  3. yarn add vue-raven

Usage

To get started, you need to configure VueRaven to use your Sentry DSN:

Bundler (Webpack, Rollup)

  1. import Vue from 'vue'
  2. import VueRaven from 'vue-raven'
  3. Vue.use(VueRaven, {
  4. dsn: 'https://<key>@sentry.io/<project>'
  5. })

Browser

  1. <!-- Include after Vue -->
  2. <!-- Local files -->
  3. <script src="vue-raven/dist/vue-raven.js"></script>
  4. <!-- From CDN -->
  5. <script src="https://unpkg.com/vue-raven"></script>
  6. <script>
  7. Vue.use(VueRaven, {
  8. dsn: 'https://<key>@sentry.io/<project>'
  9. })
  10. const app = new Vue({
  11. el: '#app',
  12. // ...
  13. })
  14. </script>

Only these settings allow VueRaven capture any uncaught exception.

Options

Option Type Default Info
dsn String null The Data Source Name
public_dsn String null If value omitted it will be generated using dsn value, by removing private key part.
public_key String null Will be ignored if dsn provided.
private_key String null Will be ignored if dsn provided.
host String sentry.io Will be ignored if dsn provided.
protocol String https Will be ignored if dsn provided.
project_Id String null Will be ignored if dsn provided.
path String null Will be ignored if dsn provided.
disableReport Boolean false Disable all reports.
disableAutoReport Boolean false Disable auto report.
environment String production Sentry’s environment.

Reporting Errors

Disable auto report

By default vueraven will report the errors captured automatically, but you can disable using the disableAutoReport option:

  1. import Vue from 'vue'
  2. import VueRaven from 'vue-raven'
  3. Vue.use(VueRaven, {
  4. dsn: 'https://<key>@sentry.io/<project>'
  5. disableAutoReport: true,
  6. })

Report errors manually

In some cases you may want to report erros manually, for this you will have the reven-js api available at the instance of the component.

  1. // my-component
  2. export default {
  3. methods: {
  4. // ...
  5. async saveUser() {
  6. try {
  7. await User.save(/* data */)
  8. } catch (err) {
  9. this.$raven.captureException(err)
  10. }
  11. }
  12. }
  13. }

or

  1. import {Raven} from 'vue-raven';
  2. // my-component
  3. export default {
  4. methods: {
  5. // ...
  6. async saveUser() {
  7. try {
  8. await User.save(/* data */)
  9. } catch (err) {
  10. Raven.captureException(err)
  11. }
  12. }
  13. }
  14. }

Live demo

We create a small example so you can see the plugin in action.

jsfiddle

error

License

MIT