Skip to content

Commit f083a2f

Browse files
authored
Merge pull request #456 from aidenkeating/INTLY-1814
INTLY-1814 Don't crash when walkthrough isn't found
2 parents 1519f3d + f7f06e9 commit f083a2f

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

server.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,18 @@ app.get('/about', (_, res) => {
131131

132132
app.get('/about/walkthrough/:walkthroughId', (req, res) => {
133133
const { walkthroughId } = req.params;
134+
const walkthrough = walkthroughs.find(w => w.id === walkthroughId);
135+
if (!walkthrough) {
136+
console.error('Could not find walkthrough with ID', walkthroughId);
137+
res.sendStatus(404);
138+
return;
139+
}
134140
res.json({
135141
walkthroughId,
136-
walkthroughLocation: getWalkthroughLocationInfoForWalkthrough(walkthroughId)
142+
walkthroughLocation: walkthrough.walkthroughLocationInfo
137143
});
138144
});
139145

140-
function getWalkthroughLocationInfoForWalkthrough(walkthroughId) {
141-
const walkthrough = walkthroughs.find(w => w.id === walkthroughId);
142-
return walkthrough.walkthroughLocationInfo;
143-
}
144-
145146
function getUniqueWalkthroughLocationInfos(walkthroughs) {
146147
const infos = {};
147148
walkthroughs.forEach(walkthrough => {

src/redux/reducers/walkthroughServiceReducers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ const walkthroughServiceReducers = (state = initialState, action) => {
107107
}
108108
);
109109
case FULFILLED_ACTION(walkthroughTypes.GET_WALKTHROUGH_INFO):
110+
if (!action.payload.data || !action.payload.data.walkthroughLocation) {
111+
return state;
112+
}
110113
return setStateProp(
111114
'walkthroughInfo',
112115
{

src/services/middlewareServices.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const getCustomConfig = (dispatch, user) => {
163163
return fetch(`/customConfig?username=${parsedUsername}`)
164164
.then(res => res.json())
165165
.then(config => {
166-
if (config && config.services) {
166+
if (config) {
167167
dispatch({
168168
type: FULFILLED_ACTION(middlewareTypes.GET_CUSTOM_CONFIG),
169169
payload: config

0 commit comments

Comments
 (0)