diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 030e97db7..c23ec696a 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -3592,16 +3592,26 @@ EOF $oPage->add_ready_script(InlineImage::EnableCKEditorImageUpload($this, $sTempId)); } else { //we can directly apply the stimuli + $sExceptionMessage = null; + try { $bApplyStimulus = $this->ApplyStimulus($sStimulus); // will write the object in the DB - if (!$bApplyStimulus) { - throw new ApplicationException(Dict::S('UI:FailedToApplyStimuli')); - } else { + } + catch (Exception $oException) { + // Catch any exception happening during the stimulus + $bApplyStimulus = false; + $sExceptionMessage = ($oException instanceof CoreCannotSaveObjectException) ? $oException->getHtmlMessage() : $oException->getMessage(); + } + finally { if ($sOwnershipToken !== null) { // Release the concurrent lock, if any iTopOwnershipLock::ReleaseLock($sClass, $iKey, $sOwnershipToken); } - - return true; + if (!$bApplyStimulus) { + // Throw an application oriented exception if necessary + throw new ApplicationException($sExceptionMessage ?? Dict::S('UI:FailedToApplyStimuli')); + } else { + return true; + } } } diff --git a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php index eb853ab24..07aedd49a 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Form/ObjectFormManager.php @@ -1222,9 +1222,18 @@ class ObjectFormManager extends FormManager } } } + catch (CoreCannotSaveObjectException $e) { + $aData['valid'] = false; + $aData['messages']['error'] += array('_main' => array($e->getHtmlMessage())); + if (false === $bExceptionLogged) { + IssueLog::Error(__METHOD__.' at line '.__LINE__.' : '.$e->getMessage()); + } + } catch (Exception $e) { $aData['valid'] = false; - $aData['messages']['error'] += array('_main' => array($e->getMessage())); + $aData['messages']['error'] += [ + '_main' => [ ($e instanceof CoreCannotSaveObjectException) ? $e->getHtmlMessage() : $e->getMessage()] + ]; if (false === $bExceptionLogged) { IssueLog::Error(__METHOD__.' at line '.__LINE__.' : '.$e->getMessage()); } diff --git a/datamodels/2.x/itop-portal-base/portal/src/Helper/ObjectFormHandlerHelper.php b/datamodels/2.x/itop-portal-base/portal/src/Helper/ObjectFormHandlerHelper.php index 775ce7bb6..0bbbcc078 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Helper/ObjectFormHandlerHelper.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Helper/ObjectFormHandlerHelper.php @@ -333,6 +333,8 @@ class ObjectFormHandlerHelper 'modal' => true, ); } + } else { + throw new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, implode('
', $aFormData['validation']['messages']['error']['_main'])); } break; diff --git a/pages/UI.php b/pages/UI.php index 48660d198..aef1f3cd0 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -1206,8 +1206,16 @@ try $bApplyTransition = $oObj->DisplayStimulusForm($oP, $sStimulus, $aPrefillFormParam); } catch (ApplicationException $e) { + $bApplyTransition = false; $sMessage = $e->getMessage(); - $sSeverity = 'info'; + $sSeverity = 'warning'; + ReloadAndDisplay($oP, $oObj, 'stimulus', $sMessage, $sSeverity); + } + catch (CoreCannotSaveObjectException $e) { + $bApplyTransition = false; + $aIssues = $e->getIssues(); + $sMessage = $e->getHtmlMessage(); + $sSeverity = 'warning'; ReloadAndDisplay($oP, $oObj, 'stimulus', $sMessage, $sSeverity); } if ($bApplyTransition) {