diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5b0aebac0f0..dd961d289e2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9489,7 +9489,7 @@ abstract class CommonObject * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers * @param int $forcechilddeletion 0=no, 1=Force deletion of children - * @return int <=0 if KO, 0=Nothing done because object has child, >0 if OK + * @return int <0 if KO, 0=Nothing done because object has child, >0 if OK */ public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion = 0) { diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index 736fd9ddc38..ce92ef5ea8e 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -293,7 +293,9 @@ class MyModuleApi extends DolibarrApi throw new RestException(401, 'Access to instance id='.$this->myobject->id.' of object not allowed for login '.DolibarrApiAccess::$user->login); } - if (!$this->myobject->delete(DolibarrApiAccess::$user)) { + if ($this->myobject->delete(DolibarrApiAccess::$user) == 0) { + throw new RestException(409, 'Error when deleting MyObject : '.$this->myobject->error); + } elseif ($this->myobject->delete(DolibarrApiAccess::$user) < 0) { throw new RestException(500, 'Error when deleting MyObject : '.$this->myobject->error); }