File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ // Create your own Account and Project at www.sentry.io
3
+ dsn : 'https://badc0bbfd4a74393bbd37e6913ecb185@sentry.io/1401462'
4
+ }
Original file line number Diff line number Diff line change @@ -2,20 +2,27 @@ const express = require('express')
2
2
const mongoose = require ( 'mongoose' )
3
3
const validate = require ( 'express-validation' )
4
4
const Youch = require ( 'youch' )
5
+ const Sentry = require ( '@sentry/node' )
5
6
6
7
const databaseConfig = require ( './config/database' )
8
+ const sentryConfig = require ( './config/sentry' )
7
9
8
10
class App {
9
11
constructor ( ) {
10
12
this . express = express ( )
11
13
this . isDev = process . env . NODE_ENV !== 'production'
12
14
15
+ this . sentry ( )
13
16
this . database ( )
14
17
this . middlewares ( )
15
18
this . routes ( )
16
19
this . exception ( )
17
20
}
18
21
22
+ sentry ( ) {
23
+ Sentry . init ( sentryConfig )
24
+ }
25
+
19
26
database ( ) {
20
27
// Docker -> 'mongo' image does not have user and password
21
28
mongoose . connect ( databaseConfig . uri , {
@@ -26,13 +33,19 @@ class App {
26
33
27
34
middlewares ( ) {
28
35
this . express . use ( express . json ( ) )
36
+ this . express . use ( Sentry . Handlers . requestHandler ( ) )
29
37
}
30
38
31
39
routes ( ) {
32
40
this . express . use ( require ( './routes' ) )
33
41
}
34
42
35
43
exception ( ) {
44
+ // Sentry Middleware
45
+ if ( process . env . NODE_ENV === 'production' ) {
46
+ this . express . use ( Sentry . Handlers . errorHandler ( ) )
47
+ }
48
+
36
49
this . express . use ( async ( err , req , res , next ) => {
37
50
// Validation Exceptions
38
51
if ( err instanceof validate . ValidationError ) {
You can’t perform that action at this time.
0 commit comments