-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Rollups] Improve Rollup Job Wizard error handling #25092
Changes from 5 commits
b891a48
4ebf0b1
cdb7b15
d0fb9a1
803e8fb
afe1212
39770a5
2f759fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { fatalError, toastNotifications } from 'ui/notify'; | ||
|
||
function createToast(error) { | ||
// Expect an error in the shape provided by Angular's $http service. | ||
if (error && error.data) { | ||
const { error: errorString, statusCode, message } = error.data; | ||
return { | ||
title: `${statusCode}: ${errorString}`, | ||
text: message, | ||
}; | ||
} | ||
} | ||
|
||
export function showApiWarning(error, title) { | ||
const toast = createToast(error); | ||
|
||
if (toast) { | ||
return toastNotifications.addWarning(toast); | ||
} | ||
|
||
// This error isn't an HTTP error, so let the fatal error screen tell the user something | ||
// unexpected happened. | ||
return fatalError(error, title); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
} | ||
|
||
export function showApiError(error, title) { | ||
const toast = createToast(error); | ||
|
||
if (toast) { | ||
return toastNotifications.addDanger(toast); | ||
} | ||
|
||
// This error isn't an HTTP error, so let the fatal error screen tell the user something | ||
// unexpected happened. | ||
return fatalError(error, title); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,14 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { toastNotifications } from 'ui/notify'; | ||
|
||
import { deleteJobs as sendDeleteJobsRequest, createNoticeableDelay } from '../../services'; | ||
import { | ||
deleteJobs as sendDeleteJobsRequest, | ||
createNoticeableDelay, | ||
showApiError, | ||
} from '../../services'; | ||
import { getDetailPanelJob } from '../selectors'; | ||
|
||
import { | ||
|
@@ -30,13 +35,21 @@ export const deleteJobs = (jobIds) => async (dispatch, getState) => { | |
type: UPDATE_JOB_FAILURE, | ||
}); | ||
|
||
return toastNotifications.addDanger(error.data.message); | ||
return showApiError(error, i18n.translate('xpack.rollupJobs.deleteAction.fatalErrorTitle', { | ||
defaultMessage: 'Rollup Job Wizard delete jobs', | ||
})); | ||
} | ||
|
||
if (jobIds.length === 1) { | ||
toastNotifications.addSuccess(`Rollup job '${jobIds[0]}' was deleted`); | ||
toastNotifications.addSuccess(i18n.translate('xpack.rollupJobs.deleteAction.successSingleNotificationTitle', { | ||
defaultMessage: `Rollup job '{jobId}' was deleted`, | ||
values: { jobId: jobIds[0] }, | ||
})); | ||
} else { | ||
toastNotifications.addSuccess(`${jobIds.length} rollup jobs were deleted`); | ||
toastNotifications.addSuccess(i18n.translate('xpack.rollupJobs.deleteAction.successMultipleNotificationTitle', { | ||
defaultMessage: '{count} rollup jobs were deleted', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to handle pluralization? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessary, since this branch of the logic only handles multiple jobs. |
||
values: { count: jobIds.length }, | ||
})); | ||
} | ||
|
||
// If we've just deleted a job we were looking at, we need to close the panel. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to implement this so that navigating to the fatal error screen didn't affect our routing logic.