From 3f30a84aa26abfbc2db7218271f19c8c3a0c2040 Mon Sep 17 00:00:00 2001 From: Douglas Hall Date: Wed, 27 Mar 2019 16:11:17 -0400 Subject: [PATCH] Display error page when unexpected errors occur. --- src/actions/ProfileActions.js | 10 ------- src/actions/ProfileActions.test.js | 10 ------- src/components/App.jsx | 2 ++ src/components/ErrorPage.jsx | 46 ++++++++++++++++++++++++++++++ src/sagas/RootSaga.js | 11 ++++--- 5 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 src/components/ErrorPage.jsx diff --git a/src/actions/ProfileActions.js b/src/actions/ProfileActions.js index b908dc0..b9a535e 100644 --- a/src/actions/ProfileActions.js +++ b/src/actions/ProfileActions.js @@ -27,11 +27,6 @@ export const fetchProfileSuccess = (account, preferences, courseCertificates) => courseCertificates, }); -export const fetchProfileFailure = error => ({ - type: FETCH_PROFILE.FAILURE, - payload: { error }, -}); - export const fetchProfileReset = () => ({ type: FETCH_PROFILE.RESET, }); @@ -114,11 +109,6 @@ export const deleteProfilePhotoReset = () => ({ type: DELETE_PROFILE_PHOTO.RESET, }); -export const deleteProfilePhotoFailure = error => ({ - type: DELETE_PROFILE_PHOTO.FAILURE, - payload: { error }, -}); - // FIELD STATE ACTIONS export const openForm = formId => ({ diff --git a/src/actions/ProfileActions.test.js b/src/actions/ProfileActions.test.js index d77c530..4fa8edf 100644 --- a/src/actions/ProfileActions.test.js +++ b/src/actions/ProfileActions.test.js @@ -18,7 +18,6 @@ import { DELETE_PROFILE_PHOTO, deleteProfilePhotoBegin, deleteProfilePhotoSuccess, - deleteProfilePhotoFailure, deleteProfilePhotoReset, deleteProfilePhoto, } from './ProfileActions'; @@ -170,15 +169,6 @@ describe('DELETE profile photo actions', () => { }; expect(deleteProfilePhotoReset()).toEqual(expectedAction); }); - - it('should create an action to signal user profile photo deletion failure', () => { - const error = 'Test failure'; - const expectedAction = { - type: DELETE_PROFILE_PHOTO.FAILURE, - payload: { error }, - }; - expect(deleteProfilePhotoFailure(error)).toEqual(expectedAction); - }); }); diff --git a/src/components/App.jsx b/src/components/App.jsx index f3643cd..05a54ce 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -14,6 +14,7 @@ import SiteHeader from './common/SiteHeader'; import ConnectedProfilePage from './ProfilePage'; import FooterLogo from '../../assets/edx-footer.png'; +import ErrorPage from './ErrorPage'; import NotFoundPage from './NotFoundPage'; class App extends Component { @@ -33,6 +34,7 @@ class App extends Component {
+ diff --git a/src/components/ErrorPage.jsx b/src/components/ErrorPage.jsx new file mode 100644 index 0000000..a24a75b --- /dev/null +++ b/src/components/ErrorPage.jsx @@ -0,0 +1,46 @@ +import React, { Component } from 'react'; +import { Button, Col, Container, Row } from 'reactstrap'; +import { FormattedMessage } from 'react-intl'; +import { Link } from 'react-router-dom'; + +import apiClient from '../config/apiClient'; + +export default class ErrorPage extends Component { + componentDidMount() {} + + render() { + const { username } = apiClient.getAuthenticationState().authentication; + + return ( + + + +

+ +

+ +
+ + + + + + + +
+ ); + } +} diff --git a/src/sagas/RootSaga.js b/src/sagas/RootSaga.js index 60e7abc..94d59d5 100644 --- a/src/sagas/RootSaga.js +++ b/src/sagas/RootSaga.js @@ -6,7 +6,6 @@ import { FETCH_PROFILE, fetchProfileBegin, fetchProfileSuccess, - fetchProfileFailure, fetchProfileReset, fetchProfile, SAVE_PROFILE, @@ -23,7 +22,6 @@ import { DELETE_PROFILE_PHOTO, deleteProfilePhotoBegin, deleteProfilePhotoSuccess, - deleteProfilePhotoFailure, deleteProfilePhotoReset, resetDrafts, } from '../actions/ProfileActions'; @@ -70,7 +68,7 @@ export function* handleFetchProfile(action) { if (e.response.status === 404) { yield put(push('/notfound')); } else { - yield put(fetchProfileFailure(e.message)); + yield put(push('/error')); } } } @@ -133,8 +131,8 @@ export function* handleSaveProfile(action) { yield put(saveProfileFailure(e.processedData.fieldErrors)); } else { LoggingService.logAPIErrorResponse(e); - // TODO: Currently failing silently on other kinds of errors yield put(saveProfileReset()); + yield put(push('/error')); } } } @@ -156,8 +154,8 @@ export function* handleSaveProfilePhoto(action) { yield put(saveProfilePhotoFailure(e.processedData)); } else { LoggingService.logAPIErrorResponse(e); - // TODO: Currently failing silently on other kinds of errors yield put(saveProfilePhotoReset()); + yield put(push('/error')); } } } @@ -176,7 +174,8 @@ export function* handleDeleteProfilePhoto(action) { yield put(deleteProfilePhotoReset()); } catch (e) { LoggingService.logAPIErrorResponse(e); - yield put(deleteProfilePhotoFailure(e.message)); + yield put(deleteProfilePhotoReset()); + yield put(push('/error')); } }