Merge pull request #1404 from shakti97/axios-error-handling

Fix(axios error handling issue)
This commit is contained in:
Cassie Tarakajian 2020-05-06 13:02:38 -04:00 committed by GitHub
commit 45b9016385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 106 additions and 53 deletions

View file

@ -27,7 +27,8 @@ export function getCollections(username) {
});
dispatch(stopLoader());
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
@ -57,7 +58,8 @@ export function createCollection(collection) {
browserHistory.push(location);
})
.catch((response) => {
.catch((error) => {
const { response } = error;
console.error('Error creating collection', response.data);
dispatch({
type: ActionTypes.ERROR,
@ -87,7 +89,8 @@ export function addToCollection(collectionId, projectId) {
return response.data;
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
@ -118,7 +121,8 @@ export function removeFromCollection(collectionId, projectId) {
return response.data;
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
@ -141,7 +145,8 @@ export function editCollection(collectionId, { name, description }) {
});
return response.data;
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
@ -164,7 +169,8 @@ export function deleteCollection(collectionId) {
});
return response.data;
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data

View file

@ -65,10 +65,13 @@ export function createFile(formProps) {
// });
dispatch(setUnsavedChanges(true));
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
}));
});
});
} else {
const id = objectID().toHexString();
dispatch({
@ -113,10 +116,13 @@ export function createFolder(formProps) {
dispatch(setProjectSavedTime(response.data.project.updatedAt));
dispatch(closeNewFolderModal());
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
}));
});
});
} else {
const id = objectID().toHexString();
dispatch({
@ -163,7 +169,8 @@ export function deleteFile(id, parentId) {
parentId
});
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data

View file

@ -8,10 +8,13 @@ function updatePreferences(formParams, dispatch) {
axios.put(`${ROOT_URL}/preferences`, formParams, { withCredentials: true })
.then(() => {
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
}));
});
});
}
export function setFontSize(value) {

View file

@ -57,10 +57,13 @@ export function getProject(id) {
dispatch(setProject(response.data));
dispatch(setUnsavedChanges(false));
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
}));
});
});
};
}
@ -161,7 +164,8 @@ export function saveProject(selectedFile = null, autosave = false) {
}
}
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch(endSavingProject());
if (response.status === 403) {
dispatch(showErrorModal('staleSession'));
@ -200,7 +204,8 @@ export function saveProject(selectedFile = null, autosave = false) {
}
}
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch(endSavingProject());
if (response.status === 403) {
dispatch(showErrorModal('staleSession'));
@ -298,10 +303,13 @@ export function cloneProject(id) {
browserHistory.push(`/${response.data.user.username}/sketches/${response.data.id}`);
dispatch(setNewProject(response.data));
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.PROJECT_SAVE_FAIL,
error: response.data
}));
});
});
});
});
};
@ -344,8 +352,8 @@ export function changeProjectName(id, newName) {
}
}
})
.catch((response) => {
console.log(response);
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.PROJECT_SAVE_FAIL,
error: response.data
@ -368,7 +376,8 @@ export function deleteProject(id) {
id
});
})
.catch((response) => {
.catch((error) => {
const { response } = error;
if (response.status === 403) {
dispatch(showErrorModal('staleSession'));
} else {

View file

@ -23,7 +23,8 @@ export function getProjects(username) {
});
dispatch(stopLoader());
})
.catch((response) => {
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data

View file

@ -65,7 +65,8 @@ export function dropzoneAcceptCallback(userId, file, done) {
file.previewTemplate.className += ' uploading'; // eslint-disable-line
done();
})
.catch((response) => {
.catch((error) => {
const { response } = error;
file.custom_status = 'rejected'; // eslint-disable-line
if (response.data && response.data.responseText && response.data.responseText.message) {
done(response.data.responseText.message);

View file

@ -26,7 +26,10 @@ export function signUpUser(previousPath, formValues) {
dispatch(justOpenedProject());
browserHistory.push(previousPath);
})
.catch(response => dispatch(authError(response.data.error)));
.catch((error) => {
const { response } = error;
dispatch(authError(response.data.error));
});
};
}
@ -82,7 +85,8 @@ export function getUser() {
preferences: response.data.preferences
});
})
.catch((response) => {
.catch((error) => {
const { response } = error;
const message = response.message || response.data.error;
dispatch(authError(message));
});
@ -98,7 +102,8 @@ export function validateSession() {
dispatch(showErrorModal('staleSession'));
}
})
.catch((response) => {
.catch((error) => {
const { response } = error;
if (response.status === 404) {
dispatch(showErrorModal('staleSession'));
}
@ -114,7 +119,10 @@ export function logoutUser() {
type: ActionTypes.UNAUTH_USER
});
})
.catch(response => dispatch(authError(response.data.error)));
.catch((error) => {
const { response } = error;
dispatch(authError(response.data.error));
});
};
}
@ -127,10 +135,13 @@ export function initiateResetPassword(formValues) {
.then(() => {
// do nothing
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
message: response.data
}));
});
});
};
}
@ -143,10 +154,13 @@ export function initiateVerification() {
.then(() => {
// do nothing
})
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
message: response.data
}));
});
});
};
}
@ -161,10 +175,13 @@ export function verifyEmailConfirmation(token) {
type: ActionTypes.EMAIL_VERIFICATION_VERIFIED,
message: response.data,
}))
.catch(response => dispatch({
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.EMAIL_VERIFICATION_INVALID,
message: response.data
}));
});
});
};
}
@ -216,7 +233,10 @@ export function updateSettings(formValues) {
dispatch(showToast(5500));
dispatch(setToastText('Settings saved.'));
})
.catch(response => Promise.reject(new Error(response.data.error)));
.catch((error) => {
const { response } = error;
Promise.reject(new Error(response.data.error));
});
}
export function createApiKeySuccess(user) {
@ -232,7 +252,10 @@ export function createApiKey(label) {
.then((response) => {
dispatch(createApiKeySuccess(response.data));
})
.catch(response => Promise.reject(new Error(response.data.error)));
.catch((error) => {
const { response } = error;
Promise.reject(new Error(response.data.error));
});
}
export function removeApiKey(keyId) {
@ -244,5 +267,8 @@ export function removeApiKey(keyId) {
user: response.data
});
})
.catch(response => Promise.reject(new Error(response.data.error)));
.catch((error) => {
const { response } = error;
Promise.reject(new Error(response.data.error));
});
}