Commit 11df1ff9 authored by Dave Pisek's avatar Dave Pisek

Make vulnerability-dismissal error more descriptive

This change adds a specific error message when a user dismisses
a vulnerability for a pipeline that no longer exists.

Changelog: changed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66722
EE: true
parent 73f7feb1
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import download from '~/lib/utils/downloader'; import download from '~/lib/utils/downloader';
import httpStatusCodes from '~/lib/utils/http_status';
import pollUntilComplete from '~/lib/utils/poll_until_complete'; import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
...@@ -210,11 +211,16 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => { ...@@ -210,11 +211,16 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => {
dispatch('receiveDismissVulnerability', updatedIssue); dispatch('receiveDismissVulnerability', updatedIssue);
toast(toastMsg); toast(toastMsg);
}) })
.catch(() => { .catch((error) => {
dispatch( const pipelineNoLongerExists =
'receiveDismissVulnerabilityError', error.response?.status === httpStatusCodes.UNPROCESSABLE_ENTITY;
s__('ciReport|There was an error dismissing the vulnerability. Please try again.'), 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'; ...@@ -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 state from 'ee/vue_shared/security_reports/store/state';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import httpStatusCodes from '~/lib/utils/http_status';
import toasted from '~/vue_shared/plugins/global_toast'; import toasted from '~/vue_shared/plugins/global_toast';
import { import {
dastFeedbacks, dastFeedbacks,
...@@ -411,27 +412,38 @@ describe('security reports actions', () => { ...@@ -411,27 +412,38 @@ describe('security reports actions', () => {
}); });
}); });
it('with error should dispatch `receiveDismissVulnerabilityError`', (done) => { describe.each`
mock.onPost('dismiss_vulnerability_path').reply(500, {}); httpStatusErrorCode | expectedErrorMessage
mockedState.vulnerabilityFeedbackPath = 'dismiss_vulnerability_path'; ${httpStatusCodes.INTERNAL_SERVER_ERROR} | ${'There was an error dismissing the vulnerability. Please try again.'}
mockedState.canReadVulnerabilityFeedback = true; ${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;
});
testAction( it('should dispatch `receiveDismissVulnerabilityError` with the correct payload', (done) => {
dismissVulnerability, mock
null, .onPost(mockedState.createVulnerabilityFeedbackDismissalPath)
mockedState, .replyOnce(httpStatusErrorCode);
[],
[ testAction(
{ dismissVulnerability,
type: 'requestDismissVulnerability', null,
}, mockedState,
{ [],
type: 'receiveDismissVulnerabilityError', [
payload: 'There was an error dismissing the vulnerability. Please try again.', {
}, type: 'requestDismissVulnerability',
], },
done, {
); type: 'receiveDismissVulnerabilityError',
payload: expectedErrorMessage,
},
],
done,
);
});
}); });
}); });
......
...@@ -38384,6 +38384,9 @@ msgstr "" ...@@ -38384,6 +38384,9 @@ msgstr ""
msgid "ciReport|Container scanning detects known vulnerabilities in your docker images." msgid "ciReport|Container scanning detects known vulnerabilities in your docker images."
msgstr "" 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" msgid "ciReport|Coverage Fuzzing"
msgstr "" 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