Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return function sentryErrorMiddleware(
error: MiddlewareError,
_req: http.IncomingMessage,
_res: http.ServerResponse,
next: (error: MiddlewareError) => void,
): void {
const shouldHandleError = (options && options.shouldHandleError) || defaultShouldHandleError;
if (shouldHandleError(error)) {
withScope(scope => {
if (_req.headers && isString(_req.headers['sentry-trace'])) {
const span = Span.fromTraceparent(_req.headers['sentry-trace'] as string);
scope.setSpan(span);
}
const eventId = captureException(error);
(_res as any).sentry = eventId;
next(error);
});
return;
}
next(error);
};
}