Skip to content

Commit f346e2a

Browse files
committed
Address review comments.
1 parent 6a2b90c commit f346e2a

File tree

2 files changed

+13
-22
lines changed
  • packages

2 files changed

+13
-22
lines changed

packages/browser/src/integrations/httpclient.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ import { eventFromUnknownInput } from '../eventbuilder';
77
export type HttpStatusCodeRange = [number, number] | number;
88
export type HttpRequestTarget = string | RegExp;
99
interface HttpClientOptions {
10-
/**
11-
* Controls whether failed requests should be captured.
12-
*
13-
* Default: false
14-
*/
15-
captureFailedRequests?: boolean;
16-
1710
/**
1811
* HTTP status codes that should be considered failed.
1912
* This array can contain tuples of `[begin, end]` (both inclusive),
@@ -55,7 +48,6 @@ export class HttpClient implements Integration {
5548
*/
5649
public constructor(options?: Partial<HttpClientOptions>) {
5750
this._options = {
58-
captureFailedRequests: false,
5951
failedRequestStatusCodes: [[500, 599]],
6052
failedRequestTargets: [/.*/],
6153
...options,
@@ -68,10 +60,6 @@ export class HttpClient implements Integration {
6860
* @param options
6961
*/
7062
public setupOnce(): void {
71-
if (!this._options.captureFailedRequests) {
72-
return;
73-
}
74-
7563
this._wrapFetch();
7664
this._wrapXHR();
7765
}
@@ -170,7 +158,6 @@ export class HttpClient implements Integration {
170158
responseCookies,
171159
});
172160

173-
// Note: Not adding request / response objects as hints for XHR
174161
captureEvent(event);
175162
}
176163
}
@@ -284,7 +271,7 @@ export class HttpClient implements Integration {
284271
}
285272

286273
/**
287-
*
274+
* Wraps `fetch` function to capture request and response data
288275
*/
289276
private _wrapFetch(): void {
290277
if (!supportsNativeFetch()) {
@@ -314,7 +301,7 @@ export class HttpClient implements Integration {
314301
}
315302

316303
/**
317-
* Wraps XMLHttpRequest to capture request and response data
304+
* Wraps XMLHttpRequest to capture request and response data
318305
*/
319306
private _wrapXHR(): void {
320307
if (!('XMLHttpRequest' in GLOBAL_OBJ)) {
@@ -358,7 +345,9 @@ export class HttpClient implements Integration {
358345
__DEBUG_BUILD__ && logger.warn('Error while extracting response event form XHR response', e);
359346
}
360347

361-
return original?.apply(xhr, onloadendArgs);
348+
if (original) {
349+
return original.apply(xhr, onloadendArgs);
350+
}
362351
};
363352
});
364353

@@ -373,7 +362,13 @@ export class HttpClient implements Integration {
373362
* @param url url to verify
374363
*/
375364
private _isSentryRequest(url: string): boolean {
376-
const dsn = getCurrentHub().getClient()?.getDsn();
365+
const client = getCurrentHub().getClient();
366+
367+
if (!client) {
368+
return false;
369+
}
370+
371+
const dsn = client.getDsn();
377372
return dsn ? url.includes(dsn.host) : false;
378373
}
379374

packages/integration-tests/suites/integrations/httpclient/init.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
7-
integrations: [
8-
new Sentry.Integrations.HttpClient({
9-
captureFailedRequests: true,
10-
}),
11-
],
7+
integrations: [new Sentry.Integrations.HttpClient()],
128
tracesSampleRate: 1,
139
sendDefaultPii: true,
1410
});

0 commit comments

Comments
 (0)