Skip to content

fix(node): [v7] Skip capturing Hapi Boom error responses #11324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion dev-packages/node-integration-tests/utils/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function createRunner(...paths: string[]) {
let withSentryServer = false;
let dockerOptions: DockerOptions | undefined;
let ensureNoErrorOutput = false;
let expectError = false;

if (testPath.endsWith('.ts')) {
flags.push('-r', 'ts-node/register');
Expand All @@ -136,6 +137,10 @@ export function createRunner(...paths: string[]) {
expectedEnvelopes.push(expected);
return this;
},
expectError: function () {
expectError = true;
return this;
},
withFlags: function (...args: string[]) {
flags.push(...args);
return this;
Expand Down Expand Up @@ -347,7 +352,18 @@ export function createRunner(...paths: string[]) {
}

const url = `http://localhost:${scenarioServerPort}${path}`;
if (method === 'get') {
if (expectError) {
try {
if (method === 'get') {
await axios.get(url, { headers });
} else {
await axios.post(url, { headers });
}
} catch (e) {
return;
}
return;
} else if (method === 'get') {
return (await axios.get(url, { headers })).data;
} else {
return (await axios.post(url, { headers })).data;
Expand Down
8 changes: 1 addition & 7 deletions packages/node/src/integrations/hapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ function isResponseObject(response: ResponseObject | Boom): response is Response
return response && (response as ResponseObject).statusCode !== undefined;
}

function isBoomObject(response: ResponseObject | Boom): response is Boom {
return response && (response as Boom).isBoom !== undefined;
}

function isErrorEvent(event: RequestEvent): event is RequestEvent {
return event && (event as RequestEvent).error !== undefined;
}
Expand Down Expand Up @@ -51,9 +47,7 @@ export const hapiErrorPlugin = {
// eslint-disable-next-line deprecation/deprecation
const transaction = getActiveTransaction();

if (request.response && isBoomObject(request.response)) {
sendErrorToSentry(request.response);
} else if (isErrorEvent(event)) {
if (isErrorEvent(event)) {
sendErrorToSentry(event.error);
}

Expand Down