Commit 9850207b authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Martin Wortschack

Ensure all mutations have 'errors' field and a proper handler

parent 250c86ea
mutation ($projectPath: ID!, $iid: String!, $healthStatus: HealthStatus) { mutation($projectPath: ID!, $iid: String!, $healthStatus: HealthStatus) {
updateIssue(input: { projectPath: $projectPath, iid: $iid, healthStatus: $healthStatus}) { updateIssue(input: { projectPath: $projectPath, iid: $iid, healthStatus: $healthStatus }) {
issue { issue {
healthStatus healthStatus
} }
errors
} }
} }
...@@ -137,7 +137,10 @@ export default { ...@@ -137,7 +137,10 @@ export default {
mutation: DeleteSnippetMutation, mutation: DeleteSnippetMutation,
variables: { id: this.snippet.id }, variables: { id: this.snippet.id },
}) })
.then(() => { .then(({ data }) => {
if (data?.destroySnippet?.errors) {
throw new Error(data?.destroySnippet?.errors[0]);
}
this.isDeleting = false; this.isDeleting = false;
this.errorMessage = undefined; this.errorMessage = undefined;
this.closeDeleteModal(); this.closeDeleteModal();
......
...@@ -33,7 +33,12 @@ export default class SidebarMediator extends CESidebarMediator { ...@@ -33,7 +33,12 @@ export default class SidebarMediator extends CESidebarMediator {
this.store.setFetchingState('status', true); this.store.setFetchingState('status', true);
return this.service return this.service
.updateWithGraphQl(updateStatusMutation, { healthStatus }) .updateWithGraphQl(updateStatusMutation, { healthStatus })
.then(({ data }) => this.store.setStatus(data?.updateIssue?.issue?.healthStatus)) .then(({ data }) => {
if (data?.updateIssue?.errors?.length > 0) {
throw data.updateIssue.errors[0];
}
this.store.setStatus(data?.updateIssue?.issue?.healthStatus);
})
.catch(error => { .catch(error => {
throw error; throw error;
}) })
......
...@@ -32,7 +32,7 @@ describe('Snippet header component', () => { ...@@ -32,7 +32,7 @@ describe('Snippet header component', () => {
const errorMsg = 'Foo bar'; const errorMsg = 'Foo bar';
const err = { message: errorMsg }; const err = { message: errorMsg };
const resolveMutate = jest.fn(() => Promise.resolve()); const resolveMutate = jest.fn(() => Promise.resolve({ data: {} }));
const rejectMutation = jest.fn(() => Promise.reject(err)); const rejectMutation = jest.fn(() => Promise.reject(err));
const mutationTypes = { const mutationTypes = {
......
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