From 0d9ae4cc8308965fd0f638218f2026573bbc2051 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 8 Aug 2016 11:29:32 +0200 Subject: [PATCH] SONAR-7920 apply feedback --- server/sonar-web/src/main/js/apps/code/utils.js | 10 ++++++---- .../apps/project-admin/links/views/CreationModal.js | 13 +++++-------- .../apps/project-admin/links/views/DeletionModal.js | 9 ++++----- .../src/main/js/components/common/modal-form.js | 4 ++++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/code/utils.js b/server/sonar-web/src/main/js/apps/code/utils.js index eb63248fb13..aaa5974a794 100644 --- a/server/sonar-web/src/main/js/apps/code/utils.js +++ b/server/sonar-web/src/main/js/apps/code/utils.js @@ -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); } } diff --git a/server/sonar-web/src/main/js/apps/project-admin/links/views/CreationModal.js b/server/sonar-web/src/main/js/apps/project-admin/links/views/CreationModal.js index a2fa0e36358..3d22d6744c2 100644 --- a/server/sonar-web/src/main/js/apps/project-admin/links/views/CreationModal.js +++ b/server/sonar-web/src/main/js/apps/project-admin/links/views/CreationModal.js @@ -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(); }); } }); diff --git a/server/sonar-web/src/main/js/apps/project-admin/links/views/DeletionModal.js b/server/sonar-web/src/main/js/apps/project-admin/links/views/DeletionModal.js index a1064dfb66e..ee27fd38d01 100644 --- a/server/sonar-web/src/main/js/apps/project-admin/links/views/DeletionModal.js +++ b/server/sonar-web/src/main/js/apps/project-admin/links/views/DeletionModal.js @@ -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(); }); }, diff --git a/server/sonar-web/src/main/js/components/common/modal-form.js b/server/sonar-web/src/main/js/components/common/modal-form.js index df9f32a1fe2..a4a54d3bc6d 100644 --- a/server/sonar-web/src/main/js/components/common/modal-form.js +++ b/server/sonar-web/src/main/js/components/common/modal-form.js @@ -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)'); -- 2.39.5