fix #22766: better API response HTTP code

This commit is contained in:
Eric Seigne
2022-11-26 00:50:45 +01:00
parent 459086b11e
commit 616e2b79ef
6 changed files with 60 additions and 12 deletions

View File

@@ -214,14 +214,17 @@ class Subscriptions extends DolibarrApi
throw new RestException(404, 'Subscription not found');
}
if (!$subscription->delete(DolibarrApiAccess::$user)) {
throw new RestException(401, 'error when deleting subscription');
$res = $subscription->delete(DolibarrApiAccess::$user);
if($res < 0) {
throw new RestException(500, "Can't delete, error occurs");
}elseif($res == 0) {
throw new RestException(409, "Can't delete, that product is probably used");
}
return array(
'success' => array(
'code' => 200,
'message' => 'subscription deleted'
'message' => 'Subscription deleted'
)
);
}