-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Merged
cjcenizal
merged 8 commits into
elastic:master
from
cjcenizal:rollup-crud-api-error-handling
Nov 5, 2018
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b891a48
Improve Rollup Job Wizard error handling.
cjcenizal 4ebf0b1
Surface error in Job List when the jobs can't be loaded.
cjcenizal cdb7b15
Remove unnecessary comment.
cjcenizal d0fb9a1
Localize index pattern validation fatal error location.
cjcenizal 803e8fb
Address i18n feedback.
cjcenizal afe1212
Don't return fatalError.
cjcenizal 39770a5
Identify origin of toasts in their titles.
cjcenizal 2f759fb
Rename createToast to createToastConfig.
cjcenizal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/rollup/public/crud_app/services/api_errors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, errorTitle) { | ||
jen-huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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: errorTitle, | ||
text: `${statusCode}: ${errorString}. ${message}`, | ||
}; | ||
} | ||
} | ||
|
||
export function showApiWarning(error, errorTitle) { | ||
const toast = createToast(error, errorTitle); | ||
|
||
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, errorTitle); | ||
} | ||
|
||
export function showApiError(error, errorTitle) { | ||
const toast = createToast(error, errorTitle); | ||
|
||
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. | ||
fatalError(error, errorTitle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.errorTitle', { | ||
defaultMessage: 'Error deleting rollup 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.