1
1
import { logger } from '@sentry/core' ;
2
- import { getHubFromCarrier , Scope } from '@sentry/hub' ;
2
+ import { getCurrentHub , Scope } from '@sentry/hub' ;
3
3
import { SentryEvent , Severity } from '@sentry/types' ;
4
4
import { forget } from '@sentry/utils/async' ;
5
5
import { serialize } from '@sentry/utils/object' ;
@@ -9,7 +9,6 @@ import * as http from 'http';
9
9
import * as os from 'os' ;
10
10
import * as url from 'url' ;
11
11
import { NodeClient } from './client' ;
12
- import { getCurrentHub } from './hub' ;
13
12
14
13
const DEFAULT_SHUTDOWN_TIMEOUT = 2000 ;
15
14
@@ -208,20 +207,22 @@ export function requestHandler(options?: {
208
207
transaction ?: boolean | TransactionTypes ;
209
208
user ?: boolean ;
210
209
version ?: boolean ;
211
- } ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( ) => void ) => void {
210
+ } ) : ( req : http . IncomingMessage , res : http . ServerResponse , next : ( error ?: any ) => void ) => void {
212
211
return function sentryRequestMiddleware (
213
212
req : http . IncomingMessage ,
214
- _res : http . ServerResponse ,
215
- next : ( ) => void ,
213
+ res : http . ServerResponse ,
214
+ next : ( error ?: any ) => void ,
216
215
) : void {
217
216
const local = domain . create ( ) ;
218
- const hub = getHubFromCarrier ( req ) ;
219
- hub . bindClient ( getCurrentHub ( ) . getClient ( ) ) ;
220
- hub . configureScope ( ( scope : Scope ) => {
221
- scope . addEventProcessor ( async ( event : SentryEvent ) => parseRequest ( event , req , options ) ) ;
222
- } ) ;
217
+ local . add ( req ) ;
218
+ local . add ( res ) ;
223
219
local . on ( 'error' , next ) ;
224
- local . run ( next ) ;
220
+ local . run ( ( ) => {
221
+ getCurrentHub ( ) . configureScope ( scope =>
222
+ scope . addEventProcessor ( async ( event : SentryEvent ) => parseRequest ( event , req , options ) ) ,
223
+ ) ;
224
+ next ( ) ;
225
+ } ) ;
225
226
} ;
226
227
}
227
228
@@ -238,7 +239,6 @@ interface MiddlewareError extends Error {
238
239
/** JSDoc */
239
240
function getStatusCodeFromResponse ( error : MiddlewareError ) : number {
240
241
const statusCode = error . status || error . statusCode || error . status_code || ( error . output && error . output . statusCode ) ;
241
-
242
242
return statusCode ? parseInt ( statusCode as string , 10 ) : 500 ;
243
243
}
244
244
@@ -251,7 +251,7 @@ export function errorHandler(): (
251
251
) => void {
252
252
return function sentryErrorMiddleware (
253
253
error : MiddlewareError ,
254
- req : http . IncomingMessage ,
254
+ _req : http . IncomingMessage ,
255
255
_res : http . ServerResponse ,
256
256
next : ( error : MiddlewareError ) => void ,
257
257
) : void {
@@ -260,7 +260,7 @@ export function errorHandler(): (
260
260
next ( error ) ;
261
261
return ;
262
262
}
263
- getHubFromCarrier ( req ) . captureException ( error , { originalException : error } ) ;
263
+ getCurrentHub ( ) . captureException ( error , { originalException : error } ) ;
264
264
next ( error ) ;
265
265
} ;
266
266
}
0 commit comments