Skip to content
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

ARSN-376 Probe response logic should be handled in the handler #2189

Merged
merged 2 commits into from
Dec 7, 2023
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
8 changes: 1 addition & 7 deletions lib/network/probe/ProbeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export class ProbeServer extends httpServer {
return;
}

const probeResponse = this._handlers.get(req.url!)!(res, log);
if (probeResponse !== undefined && probeResponse !== '') {
// Return an internal error with the response
errors.InternalError
.customizeDescription(probeResponse)
.writeResponse(res);
}
this._handlers.get(req.url!)!(res, log);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "7.10.46",
"version": "7.10.46-1",
"description": "Common utilities for the S3 project components",
"main": "build/index.js",
"repository": {
Expand Down
28 changes: 23 additions & 5 deletions tests/unit/network/probe/ProbeServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,34 @@ describe('network.probe.ProbeServer', () => {
});

it('500 response on bad probe', done => {
server.addHandler('/check', () => 'check failed');
const failedMessage = 'failed_message';
server.addHandler('/check', res => {
res.writeHead(500);
res.end(failedMessage);
});
makeRequest('GET', '/check', (err, res) => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 500);
res.setEncoding('utf8');
res.on('data', body => {
assert.strictEqual(body, failedMessage);
done();
});
});
});

it('500 response on bad async probe', done => {
const failedMessage = 'failed_message';
server.addHandler('/check', async res => {
res.writeHead(500);
res.end(failedMessage);
});
makeRequest('GET', '/check', (err, res) => {
assert.ifError(err);
assert.strictEqual(res.statusCode, 500);
res.setEncoding('utf8');
res.on('data', body => {
assert.strictEqual(
body,
'{"errorType":"InternalError","errorMessage":"check failed"}',
);
assert.strictEqual(body, failedMessage);
done();
});
});
Expand Down
Loading