Skip to content

Commit

Permalink
fix: Add fetchOrderFailure for error handling and modify handleFetchO…
Browse files Browse the repository at this point in the history
…rder with try block
  • Loading branch information
julianajlk committed Jul 27, 2022
1 parent ac028fc commit 4287db8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
19 changes: 16 additions & 3 deletions src/components/NotFoundPage.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { FormattedMessage, injectIntl } from '@edx/frontend-platform/i18n';
import PropTypes from 'prop-types';

export default function NotFoundPage() {
const NotFoundPage = (props) => {
const { error } = props;
return (
<div className="container-fluid d-flex py-5 justify-content-center align-items-start text-center">
<p className="my-0 py-5 text-muted" style={{ maxWidth: '32em' }}>
Expand All @@ -10,7 +12,18 @@ export default function NotFoundPage() {
defaultMessage="The page you're looking for is unavailable or there's an error in the URL. Please check the URL and try again."
description="error message when a page does not exist"
/>
<span>{error}</span>
</p>
</div>
);
}
};

NotFoundPage.defaultProps = {
error: null,
};

NotFoundPage.propTypes = {
error: PropTypes.string,
};

export default injectIntl(NotFoundPage);
5 changes: 5 additions & 0 deletions src/receipt/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export const fetchOrderSuccess = result => ({
payload: result,
});

export const fetchOrderFailure = error => ({
type: FETCH_ORDER.FAILURE,
payload: { error },
});

export const fetchOrderReset = () => ({
type: FETCH_ORDER.RESET,
});
6 changes: 6 additions & 0 deletions src/receipt/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const receiptPage = (state = initialState, action) => {
order: action.payload.order,
loadingReceipt: false,
};
case FETCH_ORDER.FAILURE:
return {
...state,
loadingReceiptError: action.payload.error,
loadingReceipt: false,
};
case FETCH_ORDER.RESET:
return {
...state,
Expand Down
25 changes: 16 additions & 9 deletions src/receipt/saga.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { call, put, takeEvery } from 'redux-saga/effects';
import { history } from '@edx/frontend-platform';
import { logError } from '@edx/frontend-platform/logging';

// Actions
import {
FETCH_ORDER,
fetchOrderBegin,
fetchOrderSuccess,
fetchOrderFailure,
fetchOrderReset,
} from './actions';

// Services
import * as OrderApiService from './service';

export function* handleFetchOrder(action) {
console.log('[Saga] 1.a) action', action);
const { orderToFetch } = action.payload;
// JK TODO: try and finally block? Remove console.log
console.log('[Saga] 1.b) orderToFetch:', orderToFetch);
yield put(fetchOrderBegin());
const result = yield call(OrderApiService.getOrder, orderToFetch);
console.log('[Saga] 1.c) result:', result);
yield put(fetchOrderSuccess(result));
console.log('[Saga] 1.d) success');
try {
const { orderToFetch } = action.payload;
yield put(fetchOrderBegin());
const result = yield call(OrderApiService.getOrder, orderToFetch);
yield put(fetchOrderSuccess(result));
} catch (error) {
if (error.response.status === 404) {
history.push('/notfound');
} else {
yield put(fetchOrderFailure(error.message));
logError(error);
}
}
yield put(fetchOrderReset());
}

Expand Down

0 comments on commit 4287db8

Please sign in to comment.