Skip to content

Commit

Permalink
Handle errors during buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored and clue committed Nov 20, 2017
1 parent cdf9deb commit cbf14eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Middleware/RequestBodyBufferMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __invoke(ServerRequestInterface $request, $stack)
return new Response(413, array('Content-Type' => 'text/plain'), 'Request body exceeds allowed limit');
}

return $error;
throw $error;
});
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Middleware/RequestBodyBufferMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,32 @@ function($response) use (&$exposedResponse) {

Block\await($promise, $loop);
}

/**
* @expectedException RuntimeException
*/
public function testBufferingErrorThrows()
{
$loop = Factory::create();

$stream = new ThroughStream();
$serverRequest = new ServerRequest(
'GET',
'https://example.com/',
array(),
new HttpBodyStream($stream, null)
);

$buffer = new RequestBodyBufferMiddleware(1);
$promise = $buffer(
$serverRequest,
function (ServerRequestInterface $request) {
return $request;
}
);

$stream->emit('error', array(new \RuntimeException()));

Block\await($promise, $loop);
}
}

0 comments on commit cbf14eb

Please sign in to comment.