Skip to content

Commit 7d70a48

Browse files
authored
Merge pull request #1 from php-api-clients/middleware-4.0
Middleware 4.0
2 parents 2f78571 + b7cc2b3 commit 7d70a48

File tree

4 files changed

+181
-37
lines changed

4 files changed

+181
-37
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"php": "^7.0",
13-
"api-clients/middleware": "^2.0",
13+
"api-clients/middleware": "^4.0",
1414
"api-clients/psr7-http-status-exceptions": "^1.0",
1515
"clue/buzz-react": "^1.1"
1616
},

composer.lock

Lines changed: 171 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/HttpExceptionsMiddleware.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace ApiClients\Middleware\HttpExceptions;
44

5+
use ApiClients\Foundation\Middleware\Annotation\SecondLast;
56
use ApiClients\Foundation\Middleware\MiddlewareInterface;
67
use ApiClients\Foundation\Middleware\PostTrait;
78
use ApiClients\Foundation\Middleware\PreTrait;
8-
use ApiClients\Foundation\Middleware\Priority;
99
use ApiClients\Tools\Psr7\HttpStatusExceptions\ExceptionFactory;
1010
use Clue\React\Buzz\Message\ResponseException;
1111
use React\Promise\CancellablePromiseInterface;
@@ -17,24 +17,21 @@ final class HttpExceptionsMiddleware implements MiddlewareInterface
1717
use PreTrait;
1818
use PostTrait;
1919

20-
/**
21-
* @return int
22-
*/
23-
public function priority(): int
24-
{
25-
return Priority::SECOND_LAST;
26-
}
27-
2820
/**
2921
* When $throwable is a ResponseException this method will turn it into a
3022
* HTTP status code specific exception.
3123
*
3224
* @param Throwable $throwable
3325
* @param array $options
3426
* @return CancellablePromiseInterface
27+
*
28+
* @SecondLast()
3529
*/
36-
public function error(Throwable $throwable, array $options = []): CancellablePromiseInterface
37-
{
30+
public function error(
31+
Throwable $throwable,
32+
string $transactionId,
33+
array $options = []
34+
): CancellablePromiseInterface {
3835
if (!($throwable instanceof ResponseException)) {
3936
return reject($throwable);
4037
}

tests/HttpExceptionsMiddlewareTest.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace ApiClients\Tests\Middleware\HttpExceptions;
44

5-
use ApiClients\Foundation\Middleware\Priority;
65
use ApiClients\Middleware\HttpExceptions\HttpExceptionsMiddleware;
76
use ApiClients\Tools\Psr7\HttpStatusExceptions\ExceptionFactory;
87
use ApiClients\Tools\TestUtilities\TestCase;
@@ -12,21 +11,9 @@
1211
use RingCentral\Psr7\Response;
1312
use Throwable;
1413
use function Clue\React\Block\await;
15-
use function React\Promise\reject;
1614

1715
final class HttpExceptionsMiddlewareTest extends TestCase
1816
{
19-
/**
20-
* Ensure we run second last so the last can be logging or so that stores information.
21-
*/
22-
public function testPriority()
23-
{
24-
self::assertSame(
25-
Priority::SECOND_LAST,
26-
(new HttpExceptionsMiddleware())->priority()
27-
);
28-
}
29-
3017
public function provideThrowables()
3118
{
3219
yield [
@@ -55,7 +42,7 @@ public function testException(Throwable $input, Throwable $output)
5542

5643
try {
5744
await(
58-
(new HttpExceptionsMiddleware())->error($input, []),
45+
(new HttpExceptionsMiddleware())->error($input, 'abc', []),
5946
Factory::create()
6047
);
6148
} catch (Throwable $result) {

0 commit comments

Comments
 (0)