From 70c9788a8bf97fb3850dcebe7fe6938238851a26 Mon Sep 17 00:00:00 2001 From: werewolf7160 <31860486+werewolf7160@users.noreply.github.com> Date: Fri, 5 Feb 2021 12:44:55 +0100 Subject: [PATCH] call to createCommon() return int and not bool with generated Object, the post request call to createCommon() in it and taht function return a int (id or -1 if error). but the test on the returned value is a '!', that don't return false on "-1". a post request with an sql error for example(foreign key error for my test), will always return 200 instead of 500 with the error --- htdocs/modulebuilder/template/class/api_mymodule.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index 05ca7f27d16..2e04e34dcac 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -203,7 +203,7 @@ class MyModuleApi extends DolibarrApi foreach ($request_data as $field => $value) { $this->myobject->$field = $value; } - if (!$this->myobject->create(DolibarrApiAccess::$user)) { + if ($this->myobject->create(DolibarrApiAccess::$user)<0) { throw new RestException(500, "Error creating MyObject", array_merge(array($this->myobject->error), $this->myobject->errors)); } return $this->myobject->id;