Skip to content

Commit e08e7d1

Browse files
committed
Sentry now working (only Production Mode).
1 parent 234e491 commit e08e7d1

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/config/sentry.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
// Create your own Account and Project at www.sentry.io
3+
dsn: 'https://badc0bbfd4a74393bbd37e6913ecb185@sentry.io/1401462'
4+
}

src/server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@ const express = require('express')
22
const mongoose = require('mongoose')
33
const validate = require('express-validation')
44
const Youch = require('youch')
5+
const Sentry = require('@sentry/node')
56

67
const databaseConfig = require('./config/database')
8+
const sentryConfig = require('./config/sentry')
79

810
class App {
911
constructor () {
1012
this.express = express()
1113
this.isDev = process.env.NODE_ENV !== 'production'
1214

15+
this.sentry()
1316
this.database()
1417
this.middlewares()
1518
this.routes()
1619
this.exception()
1720
}
1821

22+
sentry () {
23+
Sentry.init(sentryConfig)
24+
}
25+
1926
database () {
2027
// Docker -> 'mongo' image does not have user and password
2128
mongoose.connect(databaseConfig.uri, {
@@ -26,13 +33,19 @@ class App {
2633

2734
middlewares () {
2835
this.express.use(express.json())
36+
this.express.use(Sentry.Handlers.requestHandler())
2937
}
3038

3139
routes () {
3240
this.express.use(require('./routes'))
3341
}
3442

3543
exception () {
44+
// Sentry Middleware
45+
if (process.env.NODE_ENV === 'production') {
46+
this.express.use(Sentry.Handlers.errorHandler())
47+
}
48+
3649
this.express.use(async (err, req, res, next) => {
3750
// Validation Exceptions
3851
if (err instanceof validate.ValidationError) {

0 commit comments

Comments
 (0)