Alerts: don't dispatch empty Redux action in showAlertForError()

merge-requests/784/head
Alex Gleason 3 years ago
parent d48412c5b2
commit e8d0ff89ef
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -9,6 +9,8 @@ export const ALERT_SHOW = 'ALERT_SHOW';
export const ALERT_DISMISS = 'ALERT_DISMISS'; export const ALERT_DISMISS = 'ALERT_DISMISS';
export const ALERT_CLEAR = 'ALERT_CLEAR'; export const ALERT_CLEAR = 'ALERT_CLEAR';
const noOp = () => {};
export function dismissAlert(alert) { export function dismissAlert(alert) {
return { return {
type: ALERT_DISMISS, type: ALERT_DISMISS,
@ -32,28 +34,30 @@ export function showAlert(title = messages.unexpectedTitle, message = messages.u
} }
export function showAlertForError(error) { export function showAlertForError(error) {
if (error.response) { return (dispatch, getState) => {
const { data, status, statusText } = error.response; if (error.response) {
const { data, status, statusText } = error.response;
if (status === 502) {
return showAlert('', 'The server is down', 'error'); if (status === 502) {
return dispatch(showAlert('', 'The server is down', 'error'));
}
if (status === 404 || status === 410) {
// Skip these errors as they are reflected in the UI
return dispatch(noOp);
}
let message = statusText;
const title = `${status}`;
if (data.error) {
message = data.error;
}
return dispatch(showAlert(title, message, 'error'));
} else {
console.error(error);
return dispatch(showAlert(undefined, undefined, 'error'));
} }
};
if (status === 404 || status === 410) {
// Skip these errors as they are reflected in the UI
return {};
}
let message = statusText;
const title = `${status}`;
if (data.error) {
message = data.error;
}
return showAlert(title, message, 'error');
} else {
console.error(error);
return showAlert(undefined, undefined, 'error');
}
} }

Loading…
Cancel
Save