From c0690a67245cba98ff2822012a67bcaf0592d030 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Wed, 4 Sep 2019 13:26:18 +0200 Subject: [PATCH] Merge pull request #6116 from mzazrivec/correctly_catch_api_errors_when_creating_and_updating_ot Correctly catch & handle API errors when creating orchestration template (cherry picked from commit cf1aa2acd5d07547bf1a1899a5014bb5e50fec7f) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1767648 --- .../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',