Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show a more detailed error on Bad Request #1468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/library-authoring/add-content/AddContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,14 @@ const AddContentContainer = () => {
// We can't start editing this right away so just show a toast message:
showToast(intl.formatMessage(messages.successCreateMessage));
}
}).catch(() => {
showToast(intl.formatMessage(messages.errorCreateMessage));
}).catch((error) => {
// 400 Bad Request error usually means we've reached the library's component count limit
if (error.response.status === 400) {
const detail = error.response.data.length ? error.response.data.join(', ') : error.response.data;
showToast(intl.formatMessage(messages.errorCreateMessageWithDetail, { detail }));
} else {
showToast(intl.formatMessage(messages.errorCreateMessage));
}
});
};

Expand Down
12 changes: 10 additions & 2 deletions src/library-authoring/add-content/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ const messages = defineMessages({
},
errorCreateMessage: {
id: 'course-authoring.library-authoring.add-content.error.text',
defaultMessage: 'There was an error creating the content.',
description: 'Message when creation of content in library is on error',
defaultMessage: 'There was an error creating the content. {detail}',
description: 'Message when creation of content in library is on error.',
},
errorCreateMessageWithDetail: {
id: 'course-authoring.library-authoring.add-content.error.text-detail',
defaultMessage: 'There was an error creating the content: {detail}',
description: (
'Message when creation of content in library is on error.'
+ ' The {detail} text provides more information about the error.'
),
},
linkingComponentMessage: {
id: 'course-authoring.library-authoring.linking-collection-content.progress.text',
Expand Down
Loading