From bd3001debe4184c16a9a73f2e691bc11e9c39c0e Mon Sep 17 00:00:00 2001 From: Milan Zazrivec Date: Wed, 28 Aug 2019 11:54:35 +0200 Subject: [PATCH] Correctly catch & handle API errors when creating orchestration template https://bugzilla.redhat.com/show_bug.cgi?id=1745884 --- .../orcherstration-template-form.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/javascript/components/orchestration-template/orcherstration-template-form.js b/app/javascript/components/orchestration-template/orcherstration-template-form.js index 10127eaeecc..33b26211ca2 100644 --- a/app/javascript/components/orchestration-template/orcherstration-template-form.js +++ b/app/javascript/components/orchestration-template/orcherstration-template-form.js @@ -8,13 +8,17 @@ import MiqFormRenderer from '../../forms/data-driven-form'; import miqRedirectBack from '../../helpers/miq-redirect-back'; import orchestrationFormSchema from './orchestration-template-form.schema'; -const submitNewTemplate = (values, message) => API.post('/api/orchestration_templates', values) +const submitNewTemplate = (values, message) => API.post('/api/orchestration_templates', values, {skipErrors: [400, 500]}) .then(() => miqRedirectBack(message, 'success', '/catalog/explorer')) - .catch(() => miqSparkleOff()); + .catch((apiResult) => { + add_flash(apiResult.data.error.message, 'error'); + miqSparkleOff()}); -const updateTemplate = (values, message, otId) => API.patch(`/api/orchestration_templates/${otId}`, values) +const updateTemplate = (values, message, otId) => API.patch(`/api/orchestration_templates/${otId}`, values, {skipErrors: [400, 500]}) .then(() => miqRedirectBack(message, 'success', '/catalog/explorer')) - .catch(() => miqSparkleOff()); + .catch((apiResult) => { + add_flash(apiResult.data.error.message, 'error'); + miqSparkleOff()}); const copyTemplate = (values, message, otId) => API.post(`/api/orchestration_templates/${otId}`, { action: 'copy',