Skip to content

Commit

Permalink
feat: Adding human readable 403 error access restricted
Browse files Browse the repository at this point in the history
Signed-off-by: Farhaan Bukhsh <[email protected]>
  • Loading branch information
farhaanbukhsh committed Dec 13, 2024
1 parent b110b6b commit e2c15fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/course-outline/page-alerts/PageAlerts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,18 @@ const PageAlerts = ({
let errorList = Object.entries(errors).filter(obj => obj[1] !== null).map(([k, v]) => {
switch (v.type) {
case API_ERROR_TYPES.serverError:
let description = v.data || intl.formatMessage(messages.serverErrorAlertBody);
let alertTitle = intl.formatMessage(messages.serverErrorAlert);
if (v.status === 403) {
description = intl.formatMessage(messages.forbiddenAlertBody, {
LMS: <Hyperlink destination={`${getConfig().LMS_BASE_URL}`} target="_blank" showLaunchIcon={false}>{intl.formatMessage(messages.forbiddenAlertLmsUrl)}</Hyperlink>
});
alertTitle = intl.formatMessage(messages.forbiddenAlert);
}
return {
key: k,
desc: v.data || intl.formatMessage(messages.serverErrorAlertBody),
title: intl.formatMessage(messages.serverErrorAlert),
desc: description,
title: alertTitle,
dismissible: v.dismissible,
};
case API_ERROR_TYPES.networkError:
Expand Down Expand Up @@ -378,7 +386,7 @@ const PageAlerts = ({
dismissError={() => dispatch(dismissError(msgObj.key))}
>
<Alert.Heading>{msgObj.title}</Alert.Heading>
{msgObj.desc && <Truncate lines={2}>{msgObj.desc}</Truncate>}
{msgObj.desc}
</ErrorAlert>
) : (
<Alert
Expand Down
15 changes: 15 additions & 0 deletions src/course-outline/page-alerts/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ const messages = defineMessages({
defaultMessage: 'Network error',
description: 'Generic network error alert.',
},
forbiddenAlert: {
id: 'course-authoring.course-outline.page-alert.forbidden.title',
defaultMessage: 'Access Restricted',
description: 'Forbidden(403) alert title',
},
forbiddenAlertBody: {
id: 'course-authoring.course-outline.page-alert.forbidden.body',
defaultMessage: 'It looks like you’re trying to access a page you don’t have permission to view. Contact your admin if you think this is a mistake, or head back to the {LMS}.',
description: 'Forbidden(403) alert body',
},
forbiddenAlertLmsUrl: {
id: 'course-authoring.course-outline.page-alert.lms',
defaultMessage: 'LMS',
description: 'LMS base redirection url',
},
});

export default messages;

0 comments on commit e2c15fe

Please sign in to comment.