Skip to content
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

M3-2899 Fix: Catch deleted events errors #5079

Merged
merged 2 commits into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/store/linodes/linode.requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,27 @@ const getBackupsForLinodes = ({ data }: { data: Linode.Linode[] }) =>
Bluebird.map(data, requestMostRecentBackupForLinode);

type RequestLinodeForStoreThunk = ThunkActionCreator<void>;
export const requestLinodeForStore: RequestLinodeForStoreThunk = id => dispatch => {
_getLinode(id)
.then(response => response.data)
.then(requestMostRecentBackupForLinode)
.then(linode => {
return dispatch(upsertLinode(linode));
});
export const requestLinodeForStore: RequestLinodeForStoreThunk = id => (
dispatch,
getState
) => {
const state = getState();
/** Don't request a Linode if it's already been deleted. */
if (state.__resources.linodes.results.includes(id)) {
return _getLinode(id)
.then(response => response.data)
.then(requestMostRecentBackupForLinode)
.then(linode => {
return dispatch(upsertLinode(linode));
})
.catch(_ => {
/**
* Usually this will fire when we're requesting events for a deleted Linode.
* Should be safe to ignore, the only cost would be a stale value in the store
* (if it fails for any other reason).
*/
});
} else {
return Promise.resolve();
}
};