sforkowany z mirror/soapbox
Alerts: don't dispatch empty Redux action in showAlertForError()
rodzic
d48412c5b2
commit
e8d0ff89ef
|
@ -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) {
|
if (status === 502) {
|
||||||
return showAlert('', 'The server is down', 'error');
|
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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue