Added wp api call error handle

This commit is contained in:
Olu Amey
2021-10-02 19:32:48 -04:00
parent b78aa582b5
commit 09fc79398c
+11 -4
View File
@@ -5,13 +5,20 @@ use GuzzleHttp\Client as HTTPClient;
class WpContentsClient
{
public static function serviceGetBlogItems($apiEndpointsUrl)
{
$client = new HTTPClient();
$response = $client->request(
'GET',
"{$apiEndpointsUrl}/wordpress-data"
);
try {
$response = $client->request(
'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());
}
}