Skip to content

Instantly share code, notes, and snippets.

@phoenix-lib
Forked from DiederikvandenB/nuxt.config.js
Created June 25, 2021 14:03
Show Gist options
  • Save phoenix-lib/88951295091586fed45176bccc9a6e11 to your computer and use it in GitHub Desktop.
Save phoenix-lib/88951295091586fed45176bccc9a6e11 to your computer and use it in GitHub Desktop.

Revisions

  1. @DiederikvandenB DiederikvandenB created this gist Oct 16, 2017.
    11 changes: 11 additions & 0 deletions nuxt.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    module.exports = {
    /* ... */
    modules: [
    ['~/modules/sentry', {
    public_key: '',
    private_key: '',
    project_id: '',
    }],
    ],
    /* ... */
    };
    10 changes: 10 additions & 0 deletions sentry-client.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    /* 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();
    25 changes: 25 additions & 0 deletions sentry.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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);
    };
    });
    };