Fix return code REST similar for all api with POST

This commit is contained in:
Laurent Destailleur 2016-12-23 02:08:22 +01:00
parent 5535a126d2
commit 9e44eb0d15
20 changed files with 45 additions and 51 deletions

View File

@ -170,8 +170,8 @@ class Members extends DolibarrApi
foreach($request_data as $field => $value) {
$member->$field = $value;
}
if($member->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(503, 'Error when create member : '.$member->error);
if ($member->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating member', array_merge(array($member->error), $member->errors));
}
return $member->id;
}

View File

@ -162,8 +162,8 @@ class Subscriptions extends DolibarrApi
foreach($request_data as $field => $value) {
$subscription->$field = $value;
}
if($subscription->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(503, 'Error when create subscription : '.$subscription->error);
if ($subscription->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error when creating subscription', array_merge(array($subscription->error), $subscription->errors));
}
return $subscription->id;
}

View File

@ -269,8 +269,8 @@ class Categories extends DolibarrApi
foreach($request_data as $field => $value) {
$this->category->$field = $value;
}
if($this->category->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(503, 'Error when create category : '.$this->category->error);
if ($this->category->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error when creating category', array_merge(array($this->category->error), $this->category->errors));
}
return $this->category->id;
}

View File

@ -395,7 +395,7 @@ class CategoryApi extends DolibarrApi
$this->category->$field = $value;
}
if($this->category->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(503, 'Error when create category : '.$this->category->error);
throw new RestException(500, 'Error when create category : '.$this->category->error);
}
return $this->category->id;
}

View File

@ -194,9 +194,8 @@ class AgendaEvents extends DolibarrApi
}
$this->expensereport->lines = $lines;
}*/
if ($this->actioncomm->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->actioncomm->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating actioncomm");
if ($this->actioncomm->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating event", array_merge(array($this->actioncomm->error), $this->actioncomm->errors));
}
return $this->actioncomm->id;

View File

@ -190,9 +190,8 @@ class Proposals extends DolibarrApi
}
$this->propal->lines = $lines;
}*/
if ($this->propal->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->propal->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
if ($this->propal->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->propal->error), $this->propal->errors));
}
return $this->propal->id;

View File

@ -195,9 +195,8 @@ class Orders extends DolibarrApi
}
$this->commande->lines = $lines;
}*/
if ($this->commande->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->commande->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
if ($this->commande->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->commande->error), $this->commande->errors));
}
return $this->commande->id;

View File

@ -160,7 +160,7 @@ class BankAccounts extends DolibarrApi
$account->courant = $account->type;
if ($account->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(503, 'Error when creating account: ' . $account->error);
throw new RestException(500, 'Error creating bank account', array_merge(array($account->error), $account->errors));
}
return $account->id;
}

View File

@ -203,9 +203,8 @@ class Invoices extends DolibarrApi
$this->invoice->lines = $lines;
}*/
if ($this->invoice->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->invoice->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating invoice", array_merge(array($this->invoice->error), $this->invoice->errors));
}
return $this->invoice->id;
}

View File

@ -177,9 +177,8 @@ class ExpenseReports extends DolibarrApi
}
$this->expensereport->lines = $lines;
}*/
if ($this->expensereport->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->expensereport->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating expensereport");
if ($this->expensereport->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating expensereport", array_merge(array($this->expensereport->error), $this->expensereport->errors));
}
return $this->expensereport->id;

View File

@ -203,9 +203,8 @@ class SupplierInvoices extends DolibarrApi
$this->invoice->lines = $lines;
}*/
if ($this->invoice->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->invoice->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
if ($this->invoice->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating order", array_merge(array($this->invoice->error), $this->invoice->errors));
}
return $this->invoice->id;
}

View File

@ -275,7 +275,7 @@ class ProductApi extends DolibarrApi
}
$result = $this->product->create(DolibarrApiAccess::$user);
if($result < 0) {
throw new RestException(503,'Error when creating product : '.$this->product->error);
throw new RestException(500,'Error when creating product : '.$this->product->error);
}
return $this->product->id;

View File

@ -182,9 +182,8 @@ class Products extends DolibarrApi
foreach($request_data as $field => $value) {
$this->product->$field = $value;
}
$result = $this->product->create(DolibarrApiAccess::$user);
if($result < 0) {
throw new RestException(503,'Error when creating product : '.$this->product->error);
if ($this->product->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating product", array_merge(array($this->product->error), $this->product->errors));
}
return $this->product->id;

View File

@ -169,8 +169,8 @@ class Warehouses extends DolibarrApi
foreach($request_data as $field => $value) {
$this->warehouse->$field = $value;
}
if($this->warehouse->create(DolibarrApiAccess::$user) <= 0) {
throw new RestException(503, 'Error when create warehouse : '.$this->warehouse->error);
if ($this->warehouse->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating warehouse", array_merge(array($this->warehouse->error), $this->warehouse->errors));
}
return $this->warehouse->id;
}

View File

@ -196,9 +196,8 @@ class Projects extends DolibarrApi
}
$this->project->lines = $lines;
}*/
if ($this->project->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->project->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating project");
if ($this->project->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating project", array_merge(array($this->project->error), $this->project->errors));
}
return $this->project->id;

View File

@ -203,9 +203,8 @@ class Tasks extends DolibarrApi
}
$this->project->lines = $lines;
}*/
if ($this->task->create(DolibarrApiAccess::$user) <= 0) {
$errormsg = $this->task->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating task");
if ($this->task->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating task", array_merge(array($this->task->error), $this->task->errors));
}
return $this->task->id;

View File

@ -192,7 +192,10 @@ class Contacts extends DolibarrApi
{
$this->contact->$field = $value;
}
return $this->contact->create(DolibarrApiAccess::$user);
if ($this->contact->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors));
}
return $this->contact->id;
}
/**

View File

@ -192,7 +192,10 @@ class Thirdparties extends DolibarrApi
foreach($request_data as $field => $value) {
$this->company->$field = $value;
}
return $this->company->create(DolibarrApiAccess::$user);
if ($this->company->create(DolibarrApiAccess::$user) < 0)
throw new RestException(503, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
return $this->company->id;
}
/**

View File

@ -496,9 +496,9 @@ class Societe extends CommonObject
}
else
{
dol_syslog(get_class($this)."::Create echec update ".$this->error, LOG_ERR);
dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
$this->db->rollback();
return -3;
return -4;
}
}
else
@ -520,7 +520,7 @@ class Societe extends CommonObject
}
else
{
{
$this->db->rollback();
dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
return -3;

View File

@ -174,19 +174,16 @@ class Users extends DolibarrApi
if (!isset($request_data["lastname"]))
throw new RestException(400, "lastname field missing");*/
//assign field values
$xxx=var_export($request_data, true);
dol_syslog("xxx=".$xxx);
foreach ($request_data as $field => $value)
{
$this->useraccount->$field = $value;
}
$result = $this->useraccount->create(DolibarrApiAccess::$user);
if ($result <=0) {
throw new RestException(500, "User not created : ".$this->useraccount->error);
if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
}
return array('id'=>$result);
}
return $this->useraccount->id;
}
/**