Skip to content

Commit 7c6fffd

Browse files
committed
Fix http/https issues with old no package so tests pass
1 parent bf052f6 commit 7c6fffd

File tree

9 files changed

+19
-10
lines changed

9 files changed

+19
-10
lines changed

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@types/cookie": "0.5.2",
5252
"@types/express": "^4.17.14",
5353
"@types/lru-cache": "^5.1.0",
54-
"@types/node": "~10.17.0",
54+
"@types/node": "14.18.63",
5555
"express": "^4.17.1",
5656
"nock": "^13.0.5",
5757
"undici": "^5.21.0"

packages/node/src/handlers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ export function requestHandler(
141141
if (options && options.flushTimeout && options.flushTimeout > 0) {
142142
// eslint-disable-next-line @typescript-eslint/unbound-method
143143
const _end = res.end;
144+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
145+
// @ts-ignore I've only updated the node types and this package will soon be removed
144146
res.end = function (chunk?: any | (() => void), encoding?: string | (() => void), cb?: () => void): void {
145147
void flush(options.flushTimeout)
146148
.then(() => {

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class Http implements Integration {
206206
// It has been changed in Node 9, so for all versions equal and above, we patch `https` separately.
207207
if (NODE_VERSION.major > 8) {
208208
// eslint-disable-next-line @typescript-eslint/no-var-requires
209-
const httpsModule = require('https');
209+
const httpsModule = require('node:https');
210210
const wrappedHttpsHandlerMaker = _createWrappedRequestMethodFactory(
211211
httpsModule,
212212
this._breadcrumbs,

packages/node/src/integrations/utils/errorhandling.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export function logAndExitProcess(error: Error): void {
2020
if (client === undefined) {
2121
DEBUG_BUILD && logger.warn('No NodeClient was defined, we are exiting the process now.');
2222
global.process.exit(1);
23+
return;
2324
}
2425

2526
const options = client.getOptions();

packages/node/src/integrations/utils/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type * as http from 'http';
2-
import type * as https from 'https';
1+
import type * as http from 'node:http';
2+
import type * as https from 'node:https';
33
import { URL } from 'url';
44

55
import { NODE_VERSION } from '../../nodeVersion';

packages/node/src/proxy/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*/
2828

2929
/* eslint-disable jsdoc/require-jsdoc */
30-
import * as http from 'http';
31-
import * as https from 'https';
30+
import * as http from 'node:http';
31+
import * as https from 'node:https';
3232
import type { Readable } from 'stream';
3333
// TODO (v8): Remove this when Node < 12 is no longer supported
3434
import type { URL } from 'url';

packages/node/src/transports/http.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as http from 'http';
2-
import * as https from 'https';
1+
import * as http from 'node:http';
2+
import * as https from 'node:https';
33
import { Readable } from 'stream';
44
import { URL } from 'url';
55
import { createGzip } from 'zlib';

packages/node/test/transports/http.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable deprecation/deprecation */
12
import * as http from 'http';
23

34
import { createGunzip } from 'zlib';
@@ -50,7 +51,9 @@ function setupTestServer(
5051
res.end();
5152

5253
// also terminate socket because keepalive hangs connection a bit
53-
res.connection.end();
54+
if (res.connection) {
55+
res.connection.end();
56+
}
5457
});
5558

5659
testServer.listen(18099);

packages/node/test/transports/https.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable deprecation/deprecation */
12
import * as http from 'http';
23
import * as https from 'https';
34
import { createTransport } from '@sentry/core';
@@ -49,7 +50,9 @@ function setupTestServer(
4950
res.end();
5051

5152
// also terminate socket because keepalive hangs connection a bit
52-
res.connection.end();
53+
if (res.connection) {
54+
res.connection.end();
55+
}
5356
});
5457

5558
testServer.listen(8099);

0 commit comments

Comments
 (0)