diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-10 21:09:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-10 21:09:02 +0300 |
commit | 577bb49691b11bc8ebae3a4966153ed39af60d87 (patch) | |
tree | c34970de0f1fc58463448da0f34be13a2f3f47f9 /app/assets/javascripts/snippets | |
parent | 6cffe9ea21d0974ebd3c544a3b711ffcd35649e2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/snippets')
-rw-r--r-- | app/assets/javascripts/snippets/components/edit.vue | 6 | ||||
-rw-r--r-- | app/assets/javascripts/snippets/mixins/snippets.js | 8 | ||||
-rw-r--r-- | app/assets/javascripts/snippets/utils/error.js | 15 |
3 files changed, 26 insertions, 3 deletions
diff --git a/app/assets/javascripts/snippets/components/edit.vue b/app/assets/javascripts/snippets/components/edit.vue index 629f9b03255..4acfcd2a4d6 100644 --- a/app/assets/javascripts/snippets/components/edit.vue +++ b/app/assets/javascripts/snippets/components/edit.vue @@ -18,6 +18,7 @@ import CreateSnippetMutation from '../mutations/createSnippet.mutation.graphql'; import { getSnippetMixin } from '../mixins/snippets'; import { SNIPPET_CREATE_MUTATION_ERROR, SNIPPET_UPDATE_MUTATION_ERROR } from '../constants'; import { markBlobPerformance } from '../utils/blob'; +import { getErrorMessage } from '../utils/error'; import SnippetBlobActionsEdit from './snippet_blob_actions_edit.vue'; import SnippetVisibilityEdit from './snippet_visibility_edit.vue'; @@ -190,7 +191,10 @@ export default { } }) .catch((e) => { - this.flashAPIFailure(e); + // eslint-disable-next-line no-console + console.error('[gitlab] unexpected error while updating snippet', e); + + this.flashAPIFailure(getErrorMessage(e)); }); }, updateActions(actions) { diff --git a/app/assets/javascripts/snippets/mixins/snippets.js b/app/assets/javascripts/snippets/mixins/snippets.js index 89a88958152..7552eae97fc 100644 --- a/app/assets/javascripts/snippets/mixins/snippets.js +++ b/app/assets/javascripts/snippets/mixins/snippets.js @@ -11,10 +11,14 @@ export const getSnippetMixin = { ids: [this.snippetGid], }; }, - update: (data) => { + update(data) { const res = data.snippets.nodes[0]; + + // Set `snippet.blobs` since some child components are coupled to this. if (res) { - res.blobs = res.blobs.nodes; + // It's possible for us to not get any blobs in a response. + // In this case, we should default to current blobs. + res.blobs = res.blobs ? res.blobs.nodes : this.blobs; } return res; diff --git a/app/assets/javascripts/snippets/utils/error.js b/app/assets/javascripts/snippets/utils/error.js new file mode 100644 index 00000000000..2d5c2a64038 --- /dev/null +++ b/app/assets/javascripts/snippets/utils/error.js @@ -0,0 +1,15 @@ +import { isString } from 'lodash'; +import { __ } from '~/locale'; + +export const UNEXPECTED_ERROR = __('Unexpected error'); + +export const getErrorMessage = (e) => { + if (!e) { + return UNEXPECTED_ERROR; + } + if (isString(e)) { + return e; + } + + return e.message || e.networkError || UNEXPECTED_ERROR; +}; |