Commit dbb10821 authored by Tom Quirk's avatar Tom Quirk

Consolidate error handling in "design detail" view

Error handler added for design query in Apollo,
and error message consolidated
parent 55d9c60d
......@@ -3,6 +3,7 @@ import { ApolloMutation } from 'vue-apollo';
import Mousetrap from 'mousetrap';
import { GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import createFlash from '~/flash';
import allVersionsMixin from '../../mixins/all_versions';
import Toolbar from '../../components/toolbar/index.vue';
import DesignImage from '../../components/image.vue';
......@@ -19,7 +20,7 @@ import {
createDesignDetailFlash,
} from '../../utils/design_management_utils';
import { updateStoreAfterAddImageDiffNote } from '../../utils/cache_update';
import { ADD_DISCUSSION_COMMENT_ERROR } from '../../utils/error_messages';
import { ADD_DISCUSSION_COMMENT_ERROR, DESIGN_NOT_FOUND_ERROR } from '../../utils/error_messages';
import DESIGN_DETAIL_CONTAINER_CLASS from '../../utils/constants';
export default {
......@@ -71,14 +72,15 @@ export default {
update: data => extractDesign(data),
result({ data }) {
if (!data) {
createDesignDetailFlash(s__('DesignManagement|Could not find design, please try again.'));
this.$router.push({ name: 'designs' });
this.onQueryError(DESIGN_NOT_FOUND_ERROR);
}
if (this.$route.query.version && !this.hasValidVersion) {
createDesignDetailFlash(s__('DesignManagement|Requested design version does not exist'));
this.$router.push({ name: 'designs' });
this.onQueryError(s__('DesignManagement|Requested design version does not exist'));
}
},
error() {
this.onQueryError(DESIGN_NOT_FOUND_ERROR);
},
},
},
computed: {
......@@ -148,6 +150,12 @@ export default {
this.designVariables,
);
},
onQueryError(message) {
// because we redirect user to /designs (the issue page),
// we want to create these flashes on the issue page
createFlash(message);
this.$router.push({ name: 'designs' });
},
onMutationError(e) {
createDesignDetailFlash(ADD_DISCUSSION_COMMENT_ERROR);
throw e;
......
......@@ -15,3 +15,6 @@ export const ADD_IMAGE_DIFF_NOTE_ERROR = s__(
export const UPLOAD_DESIGN_ERROR = s__(
'DesignManagement|Error uploading a new design. Please try again',
);
export const DESIGN_NOT_FOUND_ERROR = s__(
'DesignManagement|Could not find design, please try again.',
);
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