Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


Learning error handling with the library is essential to begin. If you implement this verification directly, you immediately detect where the error comes from along with other information.
Error handling with the PHP library from the web service is done with the help of exceptions.
The principle: The treatments related to the PrestaShop web service must be within a try block which itself must be followed by a catch block to retrieve the errors and, if possible, to catch them.
Illustration:
try
{
<span style="color: #0070c0">// Execution (stops and goes in the catch block if an error occurs)</span>
}
catch
{
<span style="color: #0070c0">// Error handling (tries to catch the error or the error display)</span>
}







Example:
try{
<span style="color: #0070c0">// creating web service access</span> $webService = new PrestaShopWebservice(
'http://maboutique.com/',
'ZR92FNY5UFRERNI3O9Z5QDHWKTP3YIIT',
false);
<span style="color: #0070c0">// call to retrieve all clients</span>
$xml = $webService->get(array('resource' => 'customers'));
}
catch (PrestaShopWebserviceException $ex){ $trace = $ex->getTrace(); <span style="color: #4f81bd">// Retrieve all information on the error</span>
$errorCode = $trace[enEN:0][enEN:'args'][enEN:0]; <span style="color: #4f81bd">// Retrieve the error code</span>
if ($errorCode == 401)
echo 'Bad auth key'; else
echo 'Other error : <br />'.$ex->getMessage();
<span style="color: #4f81bd">// Shows a message related to the error</span>
}

















That means each creation or use of the library must be located within a "try" block. The "catch" block can then handle the error if it occurs during the execution of the try block.
Now we'll see how to list all customers via the web service, and then we will see the four CRUD methods.

  • No labels