javascript NuxtJS Sentry模块
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript NuxtJS Sentry模块相关的知识,希望对你有一定的参考价值。
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);
};
});
};
/* 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();
module.exports = {
/* ... */
modules: [
['~/modules/sentry', {
public_key: '',
private_key: '',
project_id: '',
}],
],
/* ... */
};
以上是关于javascript NuxtJS Sentry模块的主要内容,如果未能解决你的问题,请参考以下文章
javascript nuxtjs asyncData用法
如何测试 Sentry 是不是报告错误?
将 LiveChatInc 小部件与 NuxtJs 集成
NuxtJS 可以生成纯 HTML 吗?
NuxtJS项目——开发工具
Sentry安装使用