Skip to content

Commit

Permalink
refactor: show generic message on studio server error (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored Jun 18, 2024
1 parent db1250e commit e2ed3bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/course-outline/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ import {
const getErrorDetails = (error, dismissible = true) => {
const errorInfo = { dismissible };
if (error.response?.data) {
errorInfo.data = JSON.stringify(error.response.data);
const { data } = error.response;
if ((typeof data === 'string' && !data.includes('</html>')) || typeof data === 'object') {
errorInfo.data = JSON.stringify(data);
}
errorInfo.status = error.response.status;
errorInfo.type = API_ERROR_TYPES.serverError;
} else if (error.request) {
Expand Down
22 changes: 8 additions & 14 deletions src/course-outline/page-alerts/PageAlerts.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { uniqBy } from 'lodash';
import { getConfig } from '@edx/frontend-platform';
import { useDispatch, useSelector } from 'react-redux';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
Expand Down Expand Up @@ -336,15 +337,13 @@ const PageAlerts = ({
};

const renderApiErrors = () => {
const errorList = Object.entries(errors).filter(obj => obj[1] !== null).map(([k, v]) => {
let errorList = Object.entries(errors).filter(obj => obj[1] !== null).map(([k, v]) => {
switch (v.type) {
case API_ERROR_TYPES.serverError:
return {
key: k,
desc: v.data,
title: intl.formatMessage(messages.serverErrorAlert, {
status: v.status,
}),
desc: v.data || intl.formatMessage(messages.serverErrorAlertBody),
title: intl.formatMessage(messages.serverErrorAlert),
dismissible: v.dismissible,
};
case API_ERROR_TYPES.networkError:
Expand All @@ -356,11 +355,12 @@ const PageAlerts = ({
default:
return {
key: k,
desc: v.data,
title: v.data,
dismissible: v.dismissible,
};
}
});
errorList = uniqBy(errorList, 'title');
if (!errorList?.length) {
return null;
}
Expand All @@ -373,10 +373,7 @@ const PageAlerts = ({
key={msgObj.key}
dismissError={() => dispatch(dismissError(msgObj.key))}
>
{msgObj.title
&& (
<Alert.Heading>{msgObj.title}</Alert.Heading>
)}
<Alert.Heading>{msgObj.title}</Alert.Heading>
{msgObj.desc && <Truncate lines={2}>{msgObj.desc}</Truncate>}
</ErrorAlert>
) : (
Expand All @@ -385,10 +382,7 @@ const PageAlerts = ({
icon={ErrorIcon}
key={msgObj.key}
>
{msgObj.title
&& (
<Alert.Heading>{msgObj.title}</Alert.Heading>
)}
<Alert.Heading>{msgObj.title}</Alert.Heading>
{msgObj.desc && <Truncate lines={2}>{msgObj.desc}</Truncate>}
</Alert>
)
Expand Down
7 changes: 6 additions & 1 deletion src/course-outline/page-alerts/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ const messages = defineMessages({
},
serverErrorAlert: {
id: 'course-authoring.course-outline.page-alert.server-error.title',
defaultMessage: 'Request failed with status: {status}',
defaultMessage: 'The Studio servers encountered an error',
description: 'Generic server error alert title.',
},
serverErrorAlertBody: {
id: 'course-authoring.course-outline.page-alert.server-error.body',
defaultMessage: ' An error occurred in Studio and the page could not be loaded. Please try again in a few moments. We\'ve logged the error and our staff is currently working to resolve this error as soon as possible.',
description: 'Generic server error alert title.',
},
networkErrorAlert: {
Expand Down

0 comments on commit e2ed3bc

Please sign in to comment.