1
1
'use strict' ;
2
2
3
- var raven = require ( '../client' ) ;
4
- var parsers = require ( '../parsers' ) ;
5
- var extend = require ( '../utils' ) . extend ;
6
- var domain = require ( 'domain' ) ;
3
+ var Raven = require ( '../client' ) ;
7
4
8
5
// Legacy support
9
6
var connectMiddleware = function ( client ) {
@@ -13,30 +10,15 @@ var connectMiddleware = function (client) {
13
10
// Error handler. This should be the last item listed in middleware, but
14
11
// before any other error handlers.
15
12
connectMiddleware . errorHandler = function ( client ) {
16
- client = client instanceof raven . Client ? client : new raven . Client ( client ) ;
17
- return function ( err , req , res , next ) {
18
- var status = err . status || err . statusCode || err . status_code || 500 ;
19
-
20
- // skip anything not marked as an internal server error
21
- if ( status < 500 ) return next ( err ) ;
22
-
23
- var kwargs = parsers . parseRequest ( req ) ;
24
- if ( domain . active && domain . active . sentryContext ) {
25
- kwargs = extend ( kwargs , domain . active . sentryContext ) ;
26
- }
27
- return client . captureException ( err , kwargs , function ( result ) {
28
- res . sentry = client . getIdent ( result ) ;
29
- next ( err , req , res ) ;
30
- } ) ;
31
- } ;
13
+ client = client instanceof Raven . Client ? client : new Raven . Client ( client ) ;
14
+ return client . errorHandler ( ) ;
32
15
} ;
33
16
34
17
// Ensures asynchronous exceptions are routed to the errorHandler. This
35
18
// should be the **first** item listed in middleware.
36
19
connectMiddleware . requestHandler = function ( client ) {
37
- return function ( req , res , next ) {
38
- client . context ( { } , next , next ) ;
39
- } ;
20
+ client = client instanceof Raven . Client ? client : new Raven . Client ( client ) ;
21
+ return client . requestHandler ( ) ;
40
22
} ;
41
23
42
24
module . exports = connectMiddleware ;
0 commit comments