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
+8 -1
View File
@@ -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();
try {
$response = $client->request( $response = $client->request(
'GET', 'GET',
"{$apiEndpointsUrl}/wordpress-data" "{$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());
} }
} }