From e8d0ff89ef61b91a8fcc374a14fd428471c90f99 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 5 Oct 2021 16:13:42 -0500 Subject: [PATCH] Alerts: don't dispatch empty Redux action in showAlertForError() --- app/soapbox/actions/alerts.js | 48 +++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/app/soapbox/actions/alerts.js b/app/soapbox/actions/alerts.js index ae5e179ad..d1ba11fdb 100644 --- a/app/soapbox/actions/alerts.js +++ b/app/soapbox/actions/alerts.js @@ -9,6 +9,8 @@ export const ALERT_SHOW = 'ALERT_SHOW'; export const ALERT_DISMISS = 'ALERT_DISMISS'; export const ALERT_CLEAR = 'ALERT_CLEAR'; +const noOp = () => {}; + export function dismissAlert(alert) { return { type: ALERT_DISMISS, @@ -32,28 +34,30 @@ export function showAlert(title = messages.unexpectedTitle, message = messages.u } export function showAlertForError(error) { - if (error.response) { - const { data, status, statusText } = error.response; + return (dispatch, getState) => { + 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'); - } + }; }