Skip to content

Commit e2cdcd8

Browse files
committed
1 parent bac6a61 commit e2cdcd8

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/shared/actions/challenge.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ function getDetailsInit(challengeId) {
2929
* @return {Promise}
3030
*/
3131
function getDetailsDone(challengeId, tokenV3, tokenV2) {
32+
console.log(challengeId);
33+
if (_.isNaN(challengeId) || !_.inRange(challengeId, 9999999, 100000000)) {
34+
return Promise.reject({ errorCode: 404 });
35+
}
3236
const service = getChallengesService(tokenV3, tokenV2);
3337
const v3Promise = service.getChallenges({ id: challengeId })
34-
.then(res => res.challenges[0]);
38+
.then(res => (res.challenges && res.challenges.length > 0 ?
39+
res.challenges[0] : Promise.reject({ errorCode: 404 })));
3540
return Promise.all([
3641
v3Promise,
3742
v3Promise.then((v3) => {

src/shared/containers/challenge-detail/index.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import challengeActions from 'actions/challenge';
2424
import termsActions from 'actions/terms';
2525
import config from 'utils/config';
2626
import { BUCKETS } from 'utils/challenge-listing/buckets';
27+
import Error404 from 'components/Error404';
2728

2829
import './styles.scss';
2930

@@ -126,6 +127,9 @@ class ChallengeDetailPageContainer extends React.Component {
126127

127128
if (this.props.isLoadingChallenge) return <LoadingPagePlaceholder />;
128129

130+
if (this.props.fetchChallengeFailure &&
131+
this.props.fetchChallengeFailure.errorCode === 404) return <Error404 />;
132+
129133
return (
130134
<div styleName="outer-container">
131135
<div styleName="challenge-detail-container">
@@ -231,6 +235,7 @@ class ChallengeDetailPageContainer extends React.Component {
231235
ChallengeDetailPageContainer.defaultProps = {
232236
tokenV3: null,
233237
isLoadingChallenge: false,
238+
fetchChallengeFailure: null,
234239
loadingCheckpointResults: false,
235240
checkpointResults: null,
236241
loadingResults: false,
@@ -251,6 +256,7 @@ ChallengeDetailPageContainer.propTypes = {
251256
tokenV3: PT.string,
252257
challenge: PT.shape().isRequired,
253258
isLoadingChallenge: PT.bool,
259+
fetchChallengeFailure: PT.shape(),
254260
loadChallengeDetails: PT.func.isRequired,
255261
authTokens: PT.shape().isRequired,
256262
challengeId: PT.number.isRequired,
@@ -369,6 +375,7 @@ const mapStateToProps = (state, props) => ({
369375
state.challenge.detailsV2,
370376
Number(props.match.params.challengeId)),
371377
isLoadingChallenge: Boolean(state.challenge.loadingDetailsForChallengeId),
378+
fetchChallengeFailure: state.challenge.fetchChallengeFailure,
372379
authTokens: state.auth,
373380
tokenV2: state.auth && state.auth.tokenV2,
374381
tokenV3: state.auth && state.auth.tokenV3,
@@ -398,7 +405,7 @@ const mapDispatchToProps = (dispatch) => {
398405
dispatch(a.getDetailsInit(challengeId));
399406
dispatch(a.getDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2))
400407
.then((res) => {
401-
if (res.payload[0].track === 'DESIGN') {
408+
if (res.payload[0] && res.payload[0].track === 'DESIGN') {
402409
dispatch(a.fetchCheckpointsInit());
403410
dispatch(a.fetchCheckpointsDone(tokens.tokenV2, challengeId));
404411
}

src/shared/reducers/challenge.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ function onGetDetailsInit(state, action) {
2020
const challengeId = action.payload;
2121
return state.details && _.toString(state.details.id) !== challengeId ? {
2222
...state,
23-
fetchChallengeFailure: false,
23+
fetchChallengeFailure: null,
2424
loadingDetailsForChallengeId: challengeId,
2525
details: null,
2626
detailsV2: null,
2727
} : {
2828
...state,
29-
fetchChallengeFailure: false,
29+
fetchChallengeFailure: null,
3030
loadingDetailsForChallengeId: challengeId,
3131
};
3232
}
@@ -47,7 +47,7 @@ function onGetDetailsDone(state, action) {
4747
...state,
4848
details: null,
4949
detailsV2: null,
50-
fetchChallengeFailure: action.error,
50+
fetchChallengeFailure: action.payload,
5151
loadingDetailsForChallengeId: '',
5252
};
5353
}
@@ -65,7 +65,7 @@ function onGetDetailsDone(state, action) {
6565
...state,
6666
details,
6767
detailsV2: action.payload[1],
68-
fetchChallengeFailure: false,
68+
fetchChallengeFailure: null,
6969
loadingDetailsForChallengeId: '',
7070
};
7171
}

0 commit comments

Comments
 (0)