Skip to content

Commit 7beccde

Browse files
committed
added retry example
1 parent cc442d4 commit 7beccde

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Examples\Templates;
4+
5+
require dirname(__FILE__).'/../bootstrap.php';
6+
7+
use SparkPost\SparkPost;
8+
use GuzzleHttp\Client;
9+
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
10+
11+
$httpClient = new GuzzleAdapter(new Client());
12+
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY", "retries" => 3]);
14+
15+
$promise = $sparky->request('GET', 'message-events', [
16+
'campaign_ids' => 'CAMPAIGN_ID',
17+
]);
18+
19+
/**
20+
* If this fails with a 5xx it will have failed 4 times
21+
*/
22+
try {
23+
$response = $promise->wait();
24+
echo $response->getStatusCode()."\n";
25+
print_r($response->getBody())."\n";
26+
} catch (\Exception $e) {
27+
echo $e->getCode()."\n";
28+
echo $e->getMessage()."\n";
29+
30+
if ($e->getCode() >= 500 && $e->getCode() <= 599) {
31+
echo "Wow, this failed epically";
32+
}
33+
}

0 commit comments

Comments
 (0)