Skip to content

Instantly share code, notes, and snippets.

@DiederikvandenB
Created October 16, 2017 10:21
Show Gist options
  • Save DiederikvandenB/d86c6cb1122f8c09fb15895111875c34 to your computer and use it in GitHub Desktop.
Save DiederikvandenB/d86c6cb1122f8c09fb15895111875c34 to your computer and use it in GitHub Desktop.
NuxtJS Sentry Module
module.exports = {
/* ... */
modules: [
['~/modules/sentry', {
public_key: '',
private_key: '',
project_id: '',
}],
],
/* ... */
};
/* global options:true */
import Vue from 'vue';
import Raven from 'raven-js';
import RavenVue from 'raven-js/plugins/vue';
Raven
.config(`https://${options.public_key}@sentry.io/${options.project_id}`)
.addPlugin(RavenVue, Vue)
.install();
const Raven = require('raven');
const path = require('path');
module.exports = function sentryErrorMiddleware(options) {
// Setup raven
Raven.config(`https://${options.public_key}:${options.private_key}@sentry.io/${options.project_id}`).install();
// Register the client plugin
this.addPlugin({ src: path.resolve(__dirname, 'sentry-client.js'), options });
// Hook in to Nuxt renderer
this.nuxt.plugin('renderer', (renderer) => {
renderer.app.use(Raven.requestHandler());
// Grab Nuxt's original error middleware and overwrite it with our own
const nuxtErrorMiddleware = renderer.errorMiddleware;
renderer.errorMiddleware = (err, req, res, next) => {
// Log the error
res.sentry = Raven.captureException(err, { req });
// Call Nuxt's original error middleware
nuxtErrorMiddleware.call(renderer, err, req, res, next);
};
});
};
@serdaronedio
Copy link

Hi @DiederikvandenB ;

I came across these codes while researching on the internet. Nuxt's sentry module (@nuxtjs/sentry) does not report client-side errors. I tried this on my own localhost. Are your codes still valid?

What should I do to report client-side errors? It already exists in the current sentry module but I couldn't set it.

My configuration is here:
nuxt.config.js

  sentry: {
    dsn: 'https://*****
    publishRelease: true,
    sourceMapStyle: 'hidden-source-map',
    // disabled: TODO later
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment