Skip to content

Commit

Permalink
Revert "Handle 503 responses from the status API (#98738) (#98820)"
Browse files Browse the repository at this point in the history
This reverts commit 547018d.
  • Loading branch information
spalger committed Apr 29, 2021
1 parent 70358cc commit 83e1e66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 69 deletions.
45 changes: 0 additions & 45 deletions src/core/public/core_app/status/lib/load_status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,51 +100,6 @@ describe('response processing', () => {
expect(data.name).toEqual('My computer');
});

test('throws when an error occurs', async () => {
http.get.mockReset();

http.get.mockRejectedValue(new Error());

await expect(loadStatus({ http, notifications })).rejects.toThrowError();
expect(notifications.toasts.addDanger).toHaveBeenCalledTimes(1);
});

test('throws when a 503 occurs which does not contain an appropriate payload', async () => {
const error = new Error() as any;
error.response = { status: 503 };
error.body = {};

http.get.mockReset();
http.get.mockRejectedValue(error);

await expect(loadStatus({ http, notifications })).rejects.toThrowError();
expect(notifications.toasts.addDanger).toHaveBeenCalledTimes(1);
});

test('does not throw when a 503 occurs which contains an appropriate payload', async () => {
const error = new Error() as any;
error.response = { status: 503 };
error.body = mockedResponse;

http.get.mockReset();
http.get.mockRejectedValue(error);

const data = await loadStatus({ http, notifications });
expect(data.name).toEqual('My computer');
});

test('throws when a non-503 occurs which contains an appropriate payload', async () => {
const error = new Error() as any;
error.response = { status: 500 };
error.body = mockedResponse;

http.get.mockReset();
http.get.mockRejectedValue(error);

await expect(loadStatus({ http, notifications })).rejects.toThrowError();
expect(notifications.toasts.addDanger).toHaveBeenCalledTimes(1);
});

test('includes the plugin statuses', async () => {
const data = await loadStatus({ http, notifications });
expect(data.statuses).toEqual([
Expand Down
37 changes: 13 additions & 24 deletions src/core/public/core_app/status/lib/load_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,21 @@ export async function loadStatus({
try {
response = await http.get('/api/status');
} catch (e) {
// API returns a 503 response if not all services are available.
// In this case, we want to treat this as a successful API call, so that we can
// display Kibana's status correctly.
// 503 responses can happen for other reasons (such as proxies), so we make an educated
// guess here to determine if the response payload looks like an appropriate `StatusResponse`.
const ignoreError = e.response?.status === 503 && typeof e.body?.name === 'string';

if (ignoreError) {
response = e.body;
if ((e.response?.status ?? 0) >= 400) {
notifications.toasts.addDanger(
i18n.translate('core.statusPage.loadStatus.serverStatusCodeErrorMessage', {
defaultMessage: 'Failed to request server status with status code {responseStatus}',
values: { responseStatus: e.response?.status },
})
);
} else {
if ((e.response?.status ?? 0) >= 400) {
notifications.toasts.addDanger(
i18n.translate('core.statusPage.loadStatus.serverStatusCodeErrorMessage', {
defaultMessage: 'Failed to request server status with status code {responseStatus}',
values: { responseStatus: e.response?.status },
})
);
} else {
notifications.toasts.addDanger(
i18n.translate('core.statusPage.loadStatus.serverIsDownErrorMessage', {
defaultMessage: 'Failed to request server status. Perhaps your server is down?',
})
);
}
throw e;
notifications.toasts.addDanger(
i18n.translate('core.statusPage.loadStatus.serverIsDownErrorMessage', {
defaultMessage: 'Failed to request server status. Perhaps your server is down?',
})
);
}
throw e;
}

return {
Expand Down

0 comments on commit 83e1e66

Please sign in to comment.