Skip to content

Commit 1c43a5a

Browse files
fix(node): [v7] Skip capturing Hapi Boom error responses (#11324)
Backport of #11151 to v7 Co-authored-by: Onur Temizkan <[email protected]>
1 parent 9d680ff commit 1c43a5a

File tree

2 files changed

+18
-8
lines changed
  • dev-packages/node-integration-tests/utils
  • packages/node/src/integrations/hapi

2 files changed

+18
-8
lines changed

dev-packages/node-integration-tests/utils/runner.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export function createRunner(...paths: string[]) {
126126
let withSentryServer = false;
127127
let dockerOptions: DockerOptions | undefined;
128128
let ensureNoErrorOutput = false;
129+
let expectError = false;
129130

130131
if (testPath.endsWith('.ts')) {
131132
flags.push('-r', 'ts-node/register');
@@ -136,6 +137,10 @@ export function createRunner(...paths: string[]) {
136137
expectedEnvelopes.push(expected);
137138
return this;
138139
},
140+
expectError: function () {
141+
expectError = true;
142+
return this;
143+
},
139144
withFlags: function (...args: string[]) {
140145
flags.push(...args);
141146
return this;
@@ -347,7 +352,18 @@ export function createRunner(...paths: string[]) {
347352
}
348353

349354
const url = `http://localhost:${scenarioServerPort}${path}`;
350-
if (method === 'get') {
355+
if (expectError) {
356+
try {
357+
if (method === 'get') {
358+
await axios.get(url, { headers });
359+
} else {
360+
await axios.post(url, { headers });
361+
}
362+
} catch (e) {
363+
return;
364+
}
365+
return;
366+
} else if (method === 'get') {
351367
return (await axios.get(url, { headers })).data;
352368
} else {
353369
return (await axios.post(url, { headers })).data;

packages/node/src/integrations/hapi/index.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ function isResponseObject(response: ResponseObject | Boom): response is Response
2020
return response && (response as ResponseObject).statusCode !== undefined;
2121
}
2222

23-
function isBoomObject(response: ResponseObject | Boom): response is Boom {
24-
return response && (response as Boom).isBoom !== undefined;
25-
}
26-
2723
function isErrorEvent(event: RequestEvent): event is RequestEvent {
2824
return event && (event as RequestEvent).error !== undefined;
2925
}
@@ -51,9 +47,7 @@ export const hapiErrorPlugin = {
5147
// eslint-disable-next-line deprecation/deprecation
5248
const transaction = getActiveTransaction();
5349

54-
if (request.response && isBoomObject(request.response)) {
55-
sendErrorToSentry(request.response);
56-
} else if (isErrorEvent(event)) {
50+
if (isErrorEvent(event)) {
5751
sendErrorToSentry(event.error);
5852
}
5953

0 commit comments

Comments
 (0)