]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7920 apply feedback
authorStas Vilchik <vilchiks@gmail.com>
Mon, 8 Aug 2016 09:29:32 +0000 (11:29 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 8 Aug 2016 09:29:32 +0000 (11:29 +0200)
server/sonar-web/src/main/js/apps/code/utils.js
server/sonar-web/src/main/js/apps/project-admin/links/views/CreationModal.js
server/sonar-web/src/main/js/apps/project-admin/links/views/DeletionModal.js
server/sonar-web/src/main/js/components/common/modal-form.js

index eb63248fb13b72d327ea7ce1a278c675c6d95c7c..aaa5974a794f3d1c5f00814169d5b08f4b9b8e53 100644 (file)
@@ -164,11 +164,13 @@ export function loadMoreChildren (componentKey, page) {
 }
 
 export function parseError (error) {
+  const DEFAULT_MESSAGE = translate('default_error_message');
+
   try {
-    return error.response.json().then(r => {
-      return r.errors.map(error => error.msg).join('. ');
-    });
+    return error.response.json()
+        .then(r => r.errors.map(error => error.msg).join('. '))
+        .catch(() => DEFAULT_MESSAGE);
   } catch (ex) {
-    return Promise.resolve(translate('default_error_message'));
+    return Promise.resolve(DEFAULT_MESSAGE);
   }
 }
index a2fa0e363589aace873ada8807118b1c5342fff5..3d22d6744c28feb649d1a82ea1e064172e2268c5 100644 (file)
@@ -19,6 +19,7 @@
  */
 import ModalForm from '../../../../components/common/modal-form';
 import Template from './CreationModalTemplate.hbs';
+import { parseError } from '../../../code/utils';
 
 export default ModalForm.extend({
   template: Template,
@@ -31,14 +32,10 @@ export default ModalForm.extend({
     const url = this.$('#create-link-url').val();
 
     this.options.onCreate(name, url)
-        .then(() => {
-          this.destroy();
-        })
-        .catch(function (e) {
-          e.response.json().then(r => {
-            this.showErrors(r.errors, r.warnings);
-            this.enableForm();
-          });
+        .then(() => this.destroy())
+        .catch(e => {
+          parseError(e).then(msg => this.showSingleError(msg));
+          this.enableForm();
         });
   }
 });
index a1064dfb66e3640e362c48eeb498958783fd7758..ee27fd38d01e2bd1755302dd975e67c1b2c4010c 100644 (file)
@@ -20,6 +20,7 @@
 import ModalForm from '../../../../components/common/modal-form';
 import Template from './DeletionModalTemplate.hbs';
 import { deleteLink } from '../../../../api/projectLinks';
+import { parseError } from '../../../code/utils';
 
 export default ModalForm.extend({
   template: Template,
@@ -33,11 +34,9 @@ export default ModalForm.extend({
           this.trigger('done');
           this.destroy();
         })
-        .catch(function (e) {
-          e.response.json().then(r => {
-            this.showErrors(r.errors, r.warnings);
-            this.enableForm();
-          });
+        .catch(e => {
+          parseError(e).then(msg => this.showSingleError(msg));
+          this.enableForm();
         });
   },
 
index df9f32a1fe2e5525e05281c8996f10ea3b1bfcf5..a4a54d3bc6da4e727095ab9384d274c0ba52e35c 100644 (file)
@@ -71,6 +71,10 @@ export default ModalView.extend({
     this.ui.messagesContainer.scrollParent().scrollTop(0);
   },
 
+  showSingleError (msg) {
+    this.showErrors([{ msg }], []);
+  },
+
   disableForm () {
     const form = this.$('form');
     this.disabledFields = form.find(':input:not(:disabled)');