Added wp api call error handle
This commit is contained in:
@@ -5,13 +5,20 @@ use GuzzleHttp\Client as HTTPClient;
|
|||||||
|
|
||||||
class WpContentsClient
|
class WpContentsClient
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function serviceGetBlogItems($apiEndpointsUrl)
|
public static function serviceGetBlogItems($apiEndpointsUrl)
|
||||||
{
|
{
|
||||||
$client = new HTTPClient();
|
$client = new HTTPClient();
|
||||||
$response = $client->request(
|
try {
|
||||||
'GET',
|
$response = $client->request(
|
||||||
"{$apiEndpointsUrl}/wordpress-data"
|
'GET',
|
||||||
);
|
"{$apiEndpointsUrl}/wordpress-data",
|
||||||
|
['connect_timeout' => 2, 'timeout' => 3, 'debug' => true]
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// echo "\n".$e->getMessage()."\n";
|
||||||
|
$response= []; // empty array
|
||||||
|
}
|
||||||
return json_decode($response->getBody());
|
return json_decode($response->getBody());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user