Skip to content

Commit

Permalink
Merge branch 'main' into bug/handle-http-error-oauth-exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
jain-naman-sf authored Dec 11, 2023
2 parents bc5649c + 4d434bc commit 4213b68
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def safe_key() -> str:
],
'DEFAULT_THROTTLE_RATES': {
'anon': '4/second',
'user': '4/second'
'user': '4/second',
}

}
Expand Down
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
8 changes: 8 additions & 0 deletions metadeploy/adminapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class Meta:
class PlanTemplateViewSet(AdminAPIViewSet):
model_name = "PlanTemplate"
serializer_base = PlanTemplateSerializer
throttle_classes = []


class PlanFilter(filters.FilterSet):
Expand All @@ -150,22 +151,27 @@ class PlanViewSet(AdminAPIViewSet):
model_name = "Plan"
serializer_base = PlanSerializer
filterset_class = PlanFilter
throttle_classes = []


class PlanSlugViewSet(AdminAPIViewSet):
model_name = "PlanSlug"
throttle_classes = []


class VersionViewSet(AdminAPIViewSet):
model_name = "Version"
throttle_classes = []


class ProductCategoryViewSet(AdminAPIViewSet):
model_name = "ProductCategory"
throttle_classes = []


class AllowedListViewSet(AdminAPIViewSet):
model_name = "AllowedList"
throttle_classes = []


class AllowedListOrgSerializer(AdminAPISerializer):
Expand All @@ -175,6 +181,7 @@ class AllowedListOrgSerializer(AdminAPISerializer):
class AllowedListOrgViewSet(AdminAPIViewSet):
model_name = "AllowedListOrg"
serializer_base = AllowedListOrgSerializer
throttle_classes = []


class TranslationViewSet(viewsets.ViewSet):
Expand All @@ -194,6 +201,7 @@ class TranslationViewSet(viewsets.ViewSet):

permission_classes = [IsAPIUser]
model_name = "Translation"
throttle_classes = []

def partial_update(self, request, pk=None):
# Add or update a Translation record for each message
Expand Down
8 changes: 8 additions & 0 deletions metadeploy/adminapi/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def test_list(self, admin_api_client, plan_factory):
"meta": {"page": {"total": 1}},
}

def test_throttle(self, admin_api_client):
url = "http://testserver/admin/rest/allowedlistorgs"
for i in range(0, 4):
response = admin_api_client.get(url)

response = admin_api_client.get(url)
assert response.status_code == 200

def test_retrieve(self, admin_api_client, step_factory):
step = step_factory()
plan = step.plan
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 4213b68

Please sign in to comment.