nethubonline
Regular Pleskian
Hi all,
According to plesk/api-php-lib , I tried example codes as below:
I ran the PHP and it can create customer successfully, and then I ran it again, error was shown below. As you see, above PHP code does not echo any error, and it somehow display the error automatically. May I know how I can handle the error and display it in my own way? Thanks a lot.
According to plesk/api-php-lib , I tried example codes as below:
Code:
<?php
require 'vendor/autoload.php';
$host = 'testing.com';
$login = 'admin';
$password = '123456';
$client = new \PleskX\Api\Client($host);
$client->setCredentials($login, $password);
$client->customer()->create([
'cname' => 'Plesk',
'pname' => 'John Smith',
'login' => 'john',
'passwd' => 'secret',
'email' => '[email protected]',
]);
?>
I ran the PHP and it can create customer successfully, and then I ran it again, error was shown below. As you see, above PHP code does not echo any error, and it somehow display the error automatically. May I know how I can handle the error and display it in my own way? Thanks a lot.
Fatal error: Uncaught PleskX\Api\Exception: User account already exists. in /var/www/vhosts/test.com/httpdocs/vendor/plesk/api-php-lib/src/Api/Client.php:282 Stack trace: #0 /var/www/vhosts/test.com/httpdocs/vendor/plesk/api-php-lib/src/Api/Client.php(161): PleskX\Api\Client->_verifyResponse(Object(PleskX\Api\XmlResponse)) #1 /var/www/vhosts/test.com/httpdocs/vendor/plesk/api-php-lib/src/Api/Operator/Customer.php(23): PleskX\Api\Client->request('<?xml version="...') #2 /var/www/vhosts/test.com/httpdocs/test.php(13): PleskX\Api\Operator\Customer->create(Array) #3 {main} thrown in /var/www/vhosts/test.com/httpdocs/vendor/plesk/api-php-lib/src/Api/Client.php on line 282