Skip to content

Commit ac95fe1

Browse files
committed
pass request through to response or error
1 parent 264fa95 commit ac95fe1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/SparkPost/SparkPostPromise.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SparkPost;
44

55
use Http\Promise\Promise as HttpPromise;
6+
use Psr\Http\Message\RequestInterface as RequestInterface;
67

78
class SparkPostPromise implements HttpPromise
89
{
@@ -11,14 +12,20 @@ class SparkPostPromise implements HttpPromise
1112
*/
1213
private $promise;
1314

15+
/**
16+
* Array with the request values sent
17+
*/
18+
private $request;
19+
1420
/**
1521
* set the promise to be wrapped.
1622
*
1723
* @param HttpPromise $promise
1824
*/
19-
public function __construct(HttpPromise $promise)
25+
public function __construct(HttpPromise $promise, $request)
2026
{
2127
$this->promise = $promise;
28+
$this->request = $request;
2229
}
2330

2431
/**
@@ -29,13 +36,15 @@ public function __construct(HttpPromise $promise)
2936
*/
3037
public function then(callable $onFulfilled = null, callable $onRejected = null)
3138
{
32-
return $this->promise->then(function ($response) use ($onFulfilled) {
39+
$request = $this->request;
40+
41+
return $this->promise->then(function ($response) use ($onFulfilled, $request) {
3342
if (isset($onFulfilled)) {
34-
$onFulfilled(new SparkPostResponse($response));
43+
$onFulfilled(new SparkPostResponse($response, $request));
3544
}
36-
}, function ($exception) use ($onRejected) {
45+
}, function ($exception) use ($onRejected, $request) {
3746
if (isset($onRejected)) {
38-
$onRejected(new SparkPostException($exception));
47+
$onRejected(new SparkPostException($exception, $request));
3948
}
4049
});
4150
}
@@ -64,9 +73,9 @@ public function wait($unwrap = true)
6473
try {
6574
$response = $this->promise->wait($unwrap);
6675

67-
return $response ? new SparkPostResponse($response) : $response;
76+
return $response ? new SparkPostResponse($response, $this->request) : $response;
6877
} catch (\Exception $exception) {
69-
throw new SparkPostException($exception);
78+
throw new SparkPostException($exception, $this->request);
7079
}
7180
}
7281
}

0 commit comments

Comments
 (0)