Commit 60b95c95 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '290014-can-t-dismiss-vulnerability-from-mr-widget' into 'master'

MR-widget: Make vulnerability-dismissal error more descriptive

See merge request gitlab-org/gitlab!66722
parents 92834010 11df1ff9
import axios from '~/lib/utils/axios_utils';
import download from '~/lib/utils/downloader';
import httpStatusCodes from '~/lib/utils/http_status';
import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { visitUrl } from '~/lib/utils/url_utility';
import { s__, sprintf } from '~/locale';
......@@ -210,11 +211,16 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => {
dispatch('receiveDismissVulnerability', updatedIssue);
toast(toastMsg);
})
.catch(() => {
dispatch(
'receiveDismissVulnerabilityError',
s__('ciReport|There was an error dismissing the vulnerability. Please try again.'),
);
.catch((error) => {
const pipelineNoLongerExists =
error.response?.status === httpStatusCodes.UNPROCESSABLE_ENTITY;
const errorMessage = pipelineNoLongerExists
? s__(
'ciReport|Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again.',
)
: s__('ciReport|There was an error dismissing the vulnerability. Please try again.');
dispatch('receiveDismissVulnerabilityError', errorMessage);
});
};
......
......@@ -59,6 +59,7 @@ import * as types from 'ee/vue_shared/security_reports/store/mutation_types';
import state from 'ee/vue_shared/security_reports/store/state';
import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils';
import httpStatusCodes from '~/lib/utils/http_status';
import toasted from '~/vue_shared/plugins/global_toast';
import {
dastFeedbacks,
......@@ -411,10 +412,20 @@ describe('security reports actions', () => {
});
});
it('with error should dispatch `receiveDismissVulnerabilityError`', (done) => {
mock.onPost('dismiss_vulnerability_path').reply(500, {});
mockedState.vulnerabilityFeedbackPath = 'dismiss_vulnerability_path';
describe.each`
httpStatusErrorCode | expectedErrorMessage
${httpStatusCodes.INTERNAL_SERVER_ERROR} | ${'There was an error dismissing the vulnerability. Please try again.'}
${httpStatusCodes.UNPROCESSABLE_ENTITY} | ${'Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again.'}
`('with error "$httpStatusErrorCode"', ({ httpStatusErrorCode, expectedErrorMessage }) => {
beforeEach(() => {
mockedState.createVulnerabilityFeedbackDismissalPath = 'dismiss_vulnerability_path';
mockedState.canReadVulnerabilityFeedback = true;
});
it('should dispatch `receiveDismissVulnerabilityError` with the correct payload', (done) => {
mock
.onPost(mockedState.createVulnerabilityFeedbackDismissalPath)
.replyOnce(httpStatusErrorCode);
testAction(
dismissVulnerability,
......@@ -427,13 +438,14 @@ describe('security reports actions', () => {
},
{
type: 'receiveDismissVulnerabilityError',
payload: 'There was an error dismissing the vulnerability. Please try again.',
payload: expectedErrorMessage,
},
],
done,
);
});
});
});
describe('addDismissalComment', () => {
const vulnerability = {
......
......@@ -38369,6 +38369,9 @@ msgstr ""
msgid "ciReport|Container scanning detects known vulnerabilities in your docker images."
msgstr ""
msgid "ciReport|Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again."
msgstr ""
msgid "ciReport|Coverage Fuzzing"
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment