Commit 9c7e2fae authored by David Pisek's avatar David Pisek Committed by Natalia Tepluhina

Fix error handling for DAST on-demand profile library

* Fixes how the error translations are retrieved
* Removes global errors and moves them within the data for each
  profile type
parent 2242a56c
...@@ -33,8 +33,6 @@ export default { ...@@ -33,8 +33,6 @@ export default {
data() { data() {
return { return {
profileTypes: {}, profileTypes: {},
errorMessage: '',
errorDetails: [],
}; };
}, },
computed: { computed: {
...@@ -90,6 +88,8 @@ export default { ...@@ -90,6 +88,8 @@ export default {
this.$set(this.profileTypes, profileType, { this.$set(this.profileTypes, profileType, {
profiles: [], profiles: [],
pageInfo: {}, pageInfo: {},
errorMessage: '',
errorDetails: [],
}); });
}, },
hasMoreProfiles(profileType) { hasMoreProfiles(profileType) {
...@@ -110,37 +110,38 @@ export default { ...@@ -110,37 +110,38 @@ export default {
const profiles = profileEdges.map(({ node }) => node); const profiles = profileEdges.map(({ node }) => node);
const pageInfo = project?.[profileType].pageInfo; const pageInfo = project?.[profileType].pageInfo;
this.profileTypes[profileType] = { this.profileTypes[profileType].profiles = profiles;
profiles, this.profileTypes[profileType].pageInfo = pageInfo;
pageInfo,
};
} }
}, },
error(error) { error(error) {
this.handleError({ this.handleError({
profileType,
exception: error, exception: error,
message: this.profileSettings[profileType].i18n.errorMessages.fetchNetworkError, message: this.profileSettings[profileType].i18n.errorMessages.fetchNetworkError,
}); });
}, },
}; };
}, },
handleError({ exception, message = '', details = [] }) { handleError({ profileType, exception, message = '', details = [] }) {
Sentry.captureException(exception); Sentry.captureException(exception);
this.errorMessage = message; this.profileTypes[profileType].errorMessage = message;
this.errorDetails = details; this.profileTypes[profileType].errorDetails = details;
}, },
resetErrors() { resetErrors(profileType) {
this.errorMessage = ''; this.profileTypes[profileType].errorMessage = '';
this.errorDetails = []; this.profileTypes[profileType].errorDetails = [];
}, },
fetchMoreProfiles(profileType) { fetchMoreProfiles(profileType) {
const { const {
$apollo, $apollo,
$options: { i18n }, profileSettings: {
[profileType]: { i18n },
},
} = this; } = this;
const { pageInfo } = this.profileTypes[profileType]; const { pageInfo } = this.profileTypes[profileType];
this.resetErrors(); this.resetErrors(profileType);
$apollo.queries[profileType] $apollo.queries[profileType]
.fetchMore({ .fetchMore({
...@@ -148,7 +149,11 @@ export default { ...@@ -148,7 +149,11 @@ export default {
updateQuery: cacheUtils.appendToPreviousResult(profileType), updateQuery: cacheUtils.appendToPreviousResult(profileType),
}) })
.catch(error => { .catch(error => {
this.handleError({ exception: error, message: i18n.errorMessages.fetchNetworkError }); this.handleError({
profileType,
exception: error,
message: i18n.errorMessages.fetchNetworkError,
});
}); });
}, },
deleteProfile(profileType, profileId) { deleteProfile(profileType, profileId) {
...@@ -168,7 +173,7 @@ export default { ...@@ -168,7 +173,7 @@ export default {
}, },
} = this; } = this;
this.resetErrors(); this.resetErrors(profileType);
this.$apollo this.$apollo
.mutate({ .mutate({
...@@ -201,6 +206,7 @@ export default { ...@@ -201,6 +206,7 @@ export default {
}) })
.catch(error => { .catch(error => {
this.handleError({ this.handleError({
profileType,
exception: error, exception: error,
message: i18n.errorMessages.deletionNetworkError, message: i18n.errorMessages.deletionNetworkError,
}); });
...@@ -253,8 +259,8 @@ export default { ...@@ -253,8 +259,8 @@ export default {
<profiles-list <profiles-list
:data-testid="`${profileType}List`" :data-testid="`${profileType}List`"
:error-message="errorMessage" :error-message="profileTypes[profileType].errorMessage"
:error-details="errorDetails" :error-details="profileTypes[profileType].errorDetails"
:has-more-profiles-to-load="hasMoreProfiles(profileType)" :has-more-profiles-to-load="hasMoreProfiles(profileType)"
:is-loading="isLoadingProfiles(profileType)" :is-loading="isLoadingProfiles(profileType)"
:profiles-per-page="$options.profilesPerPage" :profiles-per-page="$options.profilesPerPage"
......
...@@ -223,7 +223,8 @@ describe('EE - DastProfiles', () => { ...@@ -223,7 +223,8 @@ describe('EE - DastProfiles', () => {
it.each` it.each`
givenData | propName | expectedPropValue givenData | propName | expectedPropValue
${{ errorMessage: 'foo' }} | ${'errorMessage'} | ${'foo'} ${{ profileTypes: { [profileType]: { errorMessage: 'foo' } } }} | ${'errorMessage'} | ${'foo'}
${{ profileTypes: { [profileType]: { errorDetails: ['foo'] } } }} | ${'errorDetails'} | ${['foo']}
${{ profileTypes: { [profileType]: { pageInfo: { hasNextPage: true } } } }} | ${'hasMoreProfilesToLoad'} | ${true} ${{ profileTypes: { [profileType]: { pageInfo: { hasNextPage: true } } } }} | ${'hasMoreProfilesToLoad'} | ${true}
${{ profileTypes: { [profileType]: { profiles: [{ foo: 'bar' }] } } }} | ${'profiles'} | ${[{ foo: 'bar' }]} ${{ profileTypes: { [profileType]: { profiles: [{ foo: 'bar' }] } } }} | ${'profiles'} | ${[{ foo: 'bar' }]}
`('passes down $propName correctly', async ({ givenData, propName, expectedPropValue }) => { `('passes down $propName correctly', async ({ givenData, propName, expectedPropValue }) => {
......
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