Skip to content

Middleware 4.0 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": "^7.0",
"api-clients/middleware": "^2.0",
"api-clients/middleware": "^4.0",
"api-clients/psr7-http-status-exceptions": "^1.0",
"clue/buzz-react": "^1.1"
},
Expand Down
182 changes: 171 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions src/HttpExceptionsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ApiClients\Middleware\HttpExceptions;

use ApiClients\Foundation\Middleware\Annotation\SecondLast;
use ApiClients\Foundation\Middleware\MiddlewareInterface;
use ApiClients\Foundation\Middleware\PostTrait;
use ApiClients\Foundation\Middleware\PreTrait;
use ApiClients\Foundation\Middleware\Priority;
use ApiClients\Tools\Psr7\HttpStatusExceptions\ExceptionFactory;
use Clue\React\Buzz\Message\ResponseException;
use React\Promise\CancellablePromiseInterface;
Expand All @@ -17,24 +17,21 @@ final class HttpExceptionsMiddleware implements MiddlewareInterface
use PreTrait;
use PostTrait;

/**
* @return int
*/
public function priority(): int
{
return Priority::SECOND_LAST;
}

/**
* When $throwable is a ResponseException this method will turn it into a
* HTTP status code specific exception.
*
* @param Throwable $throwable
* @param array $options
* @return CancellablePromiseInterface
*
* @SecondLast()
*/
public function error(Throwable $throwable, array $options = []): CancellablePromiseInterface
{
public function error(
Throwable $throwable,
string $transactionId,
array $options = []
): CancellablePromiseInterface {
if (!($throwable instanceof ResponseException)) {
return reject($throwable);
}
Expand Down
15 changes: 1 addition & 14 deletions tests/HttpExceptionsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ApiClients\Tests\Middleware\HttpExceptions;

use ApiClients\Foundation\Middleware\Priority;
use ApiClients\Middleware\HttpExceptions\HttpExceptionsMiddleware;
use ApiClients\Tools\Psr7\HttpStatusExceptions\ExceptionFactory;
use ApiClients\Tools\TestUtilities\TestCase;
Expand All @@ -12,21 +11,9 @@
use RingCentral\Psr7\Response;
use Throwable;
use function Clue\React\Block\await;
use function React\Promise\reject;

final class HttpExceptionsMiddlewareTest extends TestCase
{
/**
* Ensure we run second last so the last can be logging or so that stores information.
*/
public function testPriority()
{
self::assertSame(
Priority::SECOND_LAST,
(new HttpExceptionsMiddleware())->priority()
);
}

public function provideThrowables()
{
yield [
Expand Down Expand Up @@ -55,7 +42,7 @@ public function testException(Throwable $input, Throwable $output)

try {
await(
(new HttpExceptionsMiddleware())->error($input, []),
(new HttpExceptionsMiddleware())->error($input, 'abc', []),
Factory::create()
);
} catch (Throwable $result) {
Expand Down