Skip to content

Commit

Permalink
Merge branch 'main' into feature/disable-rate-limiting-admin-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-naman-sf authored Nov 23, 2023
2 parents 832c1d6 + 884740e commit 1449f4b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions locales_dev/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"Share Link to Installation Job": "Share Link to Installation Job",
"Show Logs": "Show Logs",
"Skipped": "Skipped",
"Something went wrong. Please try again later.": "Something went wrong. Please try again later.",
"Start Pre-Install Validation": "Start Pre-Install Validation",
"Start Pre-Install Validation on Scratch Org": "Start Pre-Install Validation on Scratch Org",
"Steps": "Steps",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"heroku-postbuild": "yarn prod"
},
"dependencies": {
"@omnistudio/omniscript-lwc-compiler": "^244.4.0",
"@react-hook/window-scroll": "^1.3.0",
"@salesforce-ux/design-system": "^2.18.1",
"@salesforce/design-system-react": "^0.10.48",
Expand Down Expand Up @@ -154,6 +153,9 @@
"webpack-dev-server": "^4.9.3",
"webpack-merge": "^5.8.0"
},
"optionalDependencies": {
"@omnistudio/omniscript-lwc-compiler": "^244.4.0"
},
"resolutions": {
"@storybook/**/ansi-regex": "^5.0.1",
"@storybook/**/glob-parent": "^5.1.2",
Expand Down
9 changes: 9 additions & 0 deletions src/js/components/apiErrors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ const ErrorToast = ({
doRemoveError: typeof removeError;
}) => {
const { t } = useTranslation();

if (
error.message &&
typeof error.message === 'string' &&
/<[a-z][\s\S]*>/i.test(error.message)
) {
error.message = t('Something went wrong. Please try again later.');
}

return (
<Toast
labels={{
Expand Down
3 changes: 3 additions & 0 deletions src/js/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const apiFetch = (
msg = body.non_field_errors;
}
}
if (response.status > 500 && response.status <= 600) {
msg = 'Something went wrong. Please try again later.';
}
dispatch(addError(msg));
const error: ApiError = new Error(msg);
error.response = response;
Expand Down
17 changes: 17 additions & 0 deletions test/js/components/apiErrors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ describe('<Errors />', () => {
return { getByText };
};

const setupforRawHTML = () => {
const errors = [
{ id: 'err1', message: '<html><div>This is Error</div></html>' },
];
const { getByText } = render(
<Errors errors={errors} doRemoveError={doRemoveError} />,
);
return { getByText };
};

test('calls window.location.reload on link click', () => {
const { getByText } = setup();

Expand All @@ -24,6 +34,13 @@ describe('<Errors />', () => {

expect(window.location.reload).toHaveBeenCalledTimes(1);
});
test('for raw html error', () => {
const { getByText } = setupforRawHTML();

expect(
getByText('Something went wrong. Please try again later.'),
).toBeVisible();
});

test('calls doRemoveError on close click', () => {
const { getByText } = setup();
Expand Down
8 changes: 8 additions & 0 deletions test/js/utils/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ describe('apiFetch', () => {
});

describe('error', () => {
test('throws Error for status code greater than 500', () => {
fetchMock.getOnce('/test/url/', { status: 503, body: {} });

expect.assertions(1);
return expect(apiFetch('/test/url/', dispatch)).rejects.toThrow(
'Something went wrong. Please try again later.',
);
});
test('throws Error without response', () => {
fetchMock.getOnce('/test/url/', { status: 500, body: {} });

Expand Down

0 comments on commit 1449f4b

Please sign in to comment.