Skip to content

Commit

Permalink
[Console] Handle the case where saving to history may throw an error (#…
Browse files Browse the repository at this point in the history
…62424)

* 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 <[email protected]>

Co-authored-by: Alison Goryachev <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Apr 6, 2020
1 parent ddc9024 commit ae9a751
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
})
Expand All @@ -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();
Expand Down Expand Up @@ -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',
}),
});
Expand Down

0 comments on commit ae9a751

Please sign in to comment.