Skip to content

Show correct error message for Create and Update mutations on Snippet

Denys Mishunov requested to merge 217727-snippet-dynamic-error-text into master

What does this MR do?

When on edit snippet form, we should show show correct error message depending on whether it's Create or Update mutation that failed. At the moment, it's hardcoded to be "update". This MR addresses this.

Screenshots

Before After
Create new snippet Screenshot_2020-05-26_at_23.10.20 Screenshot_2020-05-26_at_23.08.16
Update existing snippet Screenshot_2020-05-26_at_23.10.38 Screenshot_2020-05-26_at_23.08.46

Click-testing steps

  1. Enable :snippets_edit_vue feature flag in Rails console

New Snippet

  1. Go to /snippets/new
  2. On the edit form for the snippet, type in the illegal File path for the snippet (invalid://file/path for example)
  3. Click save
  4. The error flash should be shown with the correct message for CREATE scenario

Existing Snippet

This scenario has another bug, addressed in !33107 (merged) so isn't trivial to test without either setting a debugger into the code or applying this small patch:

Index: app/assets/javascripts/snippets/components/edit.vue
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- app/assets/javascripts/snippets/components/edit.vue	(revision 0e18c7fdb4adf32adfc74767f363a4ea3951bb94)
+++ app/assets/javascripts/snippets/components/edit.vue	(date 1590527350478)
@@ -147,8 +147,9 @@
           const errors = baseObj?.errors;
           if (errors.length) {
             this.flashAPIFailure(errors[0]);
-          }
-          redirectTo(baseObj.snippet.webUrl);
+          } else {
+            redirectTo(baseObj.snippet.webUrl);
+          }
         })
         .catch(e => {
           this.isUpdating = false;
  1. Go to any existing snippet. Click "Edit"
  2. On the edit form for the snippet, type in the illegal File path for the snippet (invalid://file/path for example)
  3. Click save
  4. The error flash should be shown with the correct message for UPDATE scenario

Does this MR meet the acceptance criteria?

Since this feature is still behind the feature flag, no Changelog entry has been provided.

Conformity

Availability and Testing

References #217727 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports