diff --git a/src/redux/actionCreators.js b/src/redux/actionCreators.js index 8204fdd9..ba0b393e 100644 --- a/src/redux/actionCreators.js +++ b/src/redux/actionCreators.js @@ -12,10 +12,6 @@ export function requestUnloadedSkin(index) { } export function selectedSkin(hash, position) { - if (hash == null) { - // trying to narrow down: https://sentry.io/share/issue/04b1bc5c2a764addac4e62dea201096a/ - throw new Error("Tried to select a null skin"); - } return { type: "SELECTED_SKIN", hash, position }; } @@ -148,3 +144,7 @@ export function toggleFileExplorer() { export function closeFileExlporer() { return { type: "CLOSE_FILE_EXPLORER" }; } + +export function alert(message) { + return { type: "ALERT", message }; +} diff --git a/src/redux/epics.js b/src/redux/epics.js index 05683c6d..b5dd5782 100644 --- a/src/redux/epics.js +++ b/src/redux/epics.js @@ -147,7 +147,20 @@ const searchEpic = (actions) => const randomSkinEpic = (actions, states) => actions.pipe( filter((action) => action.type === "REQUESTED_RANDOM_SKIN"), - map(() => Actions.selectedSkin(Selectors.getRandomSkinHash(states.value))) + map(() => Selectors.getRandomSkinHash(states.value)), + map((md5) => { + if (md5 == null) { + return Actions.alert("No skins found."); + } + return Actions.selectedSkin(md5); + }) + ); + +const alertEpic = (actions) => + actions.pipe( + filter((action) => action.type === "ALERT"), + tap(({ message }) => alert(message)), + ignoreElements() ); const chunkState = {}; @@ -440,17 +453,21 @@ const markNsfwEpic = (actions) => { filter((action) => action.type === "MARK_NSFW"), mergeMap(async ({ hash }) => { try { - await fetch(`${API_URL}/skins/${hash}/report`, { + const response = await fetch(`${API_URL}/skins/${hash}/report`, { method: "POST", mode: "cors", }); + if (!response.ok) { + throw new Error("Failed to report skin."); + } } catch (e) { - alert("Oops. Something went wrong. Please try again later."); - return; + return Actions.alert( + "Oops. Something went wrong. Please try again later." + ); } - alert("Thanks for reporting. We'll review this skin."); + return Actions.alert("Thanks for reporting. We'll review this skin."); }), - ignoreElements() + filter(Boolean) ); }; @@ -473,5 +490,6 @@ export default combineEpics( urlEpic, loggingEpic, skinDataEpic, - markNsfwEpic + markNsfwEpic, + alertEpic );