mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Console] Fix incorrect output message when status code is 200 and body is empty (#199975)
This commit is contained in:
parent
76664a27a9
commit
35c2a9e31e
2 changed files with 27 additions and 3 deletions
|
@ -157,10 +157,18 @@ export function sendRequest(args: RequestArgs): Promise<RequestResult[]> {
|
|||
|
||||
const { statusCode, statusText } = extractStatusCodeAndText(response, path);
|
||||
|
||||
if (body) {
|
||||
value = JSON.stringify(body, null, 2);
|
||||
// When the request is sent, the HTTP library tries to parse the response body as JSON.
|
||||
// However, if the response body is empty or not in valid JSON format, it throws an error.
|
||||
// To handle this, if the request resolves with a 200 status code but has an empty or invalid body,
|
||||
// we should still display a success message to the user.
|
||||
if (statusCode === 200 && body === null) {
|
||||
value = 'OK';
|
||||
} else {
|
||||
value = 'Request failed to get to the server (status code: ' + statusCode + ')';
|
||||
if (body) {
|
||||
value = JSON.stringify(body, null, 2);
|
||||
} else {
|
||||
value = 'Request failed to get to the server (status code: ' + statusCode + ')';
|
||||
}
|
||||
}
|
||||
|
||||
if (isMultiRequest) {
|
||||
|
|
|
@ -223,5 +223,21 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
expect(await PageObjects.console.hasSuccessBadge()).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('Shows OK when status code is 200 but body is empty', async () => {
|
||||
await PageObjects.console.clearEditorText();
|
||||
|
||||
// This request will return 200 but with an empty body
|
||||
await PageObjects.console.enterText(
|
||||
'POST /_cluster/voting_config_exclusions?node_names=node'
|
||||
);
|
||||
await PageObjects.console.clickPlay();
|
||||
|
||||
await retry.try(async () => {
|
||||
const actualResponse = await PageObjects.console.getOutputText();
|
||||
log.debug(actualResponse);
|
||||
expect(actualResponse).to.contain('OK');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue