[Console] Handle the case where saving to history may throw an error (#62424) (#62565)

* Handle the case where saving to history may throw an error

We should still show the request result even if localStorage is
full (or any other save error occurs)

* Update src/plugins/console/public/application/hooks/use_send_current_request_to_es/use_send_current_request_to_es.ts

Co-Authored-By: Alison Goryachev <alisonmllr20@gmail.com>

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Alison Goryachev <alisonmllr20@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2020-04-06 11:52:40 +02:00 committed by GitHub
parent 6b36427959
commit 423d18cbd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,7 +39,7 @@ export const useSendCurrentRequestToES = () => {
const requests = await editor.getRequestsInRange();
if (!requests.length) {
notifications.toasts.add(
i18n.translate('console.notification.noReqeustSelectedTitle', {
i18n.translate('console.notification.error.noRequestSelectedTitle', {
defaultMessage:
'No request selected. Select a request by placing the cursor inside it.',
})
@ -55,7 +55,16 @@ export const useSendCurrentRequestToES = () => {
const results = await sendRequestToES({ requests });
results.forEach(({ request: { path, method, data } }) => {
history.addToHistory(path, method, data);
try {
history.addToHistory(path, method, data);
} catch (e) {
// Best effort, but notify the user.
notifications.toasts.addError(e, {
title: i18n.translate('console.notification.error.couldNotSaveRequestTitle', {
defaultMessage: 'Could not save request to history.',
}),
});
}
});
const { polling } = settings.toJSON();
@ -85,7 +94,7 @@ export const useSendCurrentRequestToES = () => {
payload: undefined,
});
notifications.toasts.addError(e, {
title: i18n.translate('console.notification.unknownRequestErrorTitle', {
title: i18n.translate('console.notification.error.unknownErrorTitle', {
defaultMessage: 'Unknown Request Error',
}),
});