-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathClientCallPlugin.php
More file actions
40 lines (31 loc) · 1.01 KB
/
ClientCallPlugin.php
File metadata and controls
40 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace Shapecode\FUT\Client\Http\Plugin;
use Http\Client\Common\Plugin;
use Http\Client\Exception;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Shapecode\FUT\Client\Http\ClientCall;
class ClientCallPlugin implements Plugin
{
/** @var ClientCall */
protected $call;
public function __construct(ClientCall $call)
{
$this->call = $call;
}
public function handleRequest(RequestInterface $request, callable $next, callable $first) : Promise
{
$this->call->setRequest($request);
return $next($request)->then(function (ResponseInterface $response) {
$this->call->setResponse($response);
return $response;
}, function (Exception $exception) : void {
if ($exception instanceof Exception\HttpException) {
$this->call->setResponse($exception->getResponse());
}
throw $exception;
});
}
}