[Index Management] Fix empty error toasts from index actions (#162656)

Fixes https://github.com/elastic/kibana/issues/156980
Fixes https://github.com/elastic/kibana/issues/123986
Addresses https://github.com/elastic/kibana/issues/162218

## Summary

This PR fixes the empty error toasts that are displayed when an index
action (delete, open, close, flush, etc.) is unsuccessful. The errors
from each of these actions are handled by the
[handleEsError](a3c0914dae/src/plugins/es_ui_shared/__packages_do_not_import__/errors/handle_es_error.ts (L24))
function which is why we need to use the `error.body.message` field to
get a correct error message (instead of `error.message` which is
undefined).

**How to test:**
Start Kibana and perform an invalid action on some index.
For example, to test the error toast from the Delete action, delete a
hidden index that is a write index of an existing data stream:

<img width="1553" alt="Screenshot 2023-07-27 at 18 19 52"
src="91b5e5db-3c1c-4c15-addd-83bedfac6785">

---------

Co-authored-by: Yulia Čech <6585477+yuliacech@users.noreply.github.com>
This commit is contained in:
Elena Stoeva 2023-07-28 15:11:51 +01:00 committed by GitHub
parent c2219ba189
commit 3eda5fca4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 9 additions and 9 deletions

View file

@ -21,7 +21,7 @@ export const clearCacheIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -19,7 +19,7 @@ export const closeIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -18,7 +18,7 @@ export const deleteIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
notificationService.showSuccessToast(

View file

@ -20,7 +20,7 @@ export const flushIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -20,7 +20,7 @@ export const forcemergeIndices =
try {
await request(indexNames, maxNumSegments);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -20,7 +20,7 @@ export const openIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -20,7 +20,7 @@ export const refreshIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));

View file

@ -23,7 +23,7 @@ export const reloadIndices = (indexNames, options) => async (dispatch) => {
if (error.status === 404 || error.status === 403) {
return dispatch(loadIndices());
}
return notificationService.showDangerToast(error.message);
return notificationService.showDangerToast(error.body.message);
}
if (indices && indices.length > 0) {
return dispatch(reloadIndicesSuccess({ indices }));

View file

@ -20,7 +20,7 @@ export const unfreezeIndices =
try {
await request(indexNames);
} catch (error) {
notificationService.showDangerToast(error.message);
notificationService.showDangerToast(error.body.message);
return dispatch(clearRowStatus({ indexNames }));
}
dispatch(reloadIndices(indexNames));