[HttpKernel] moved some mis-placed logic to FlattenException
This commit is contained in:
parent
fdf320d642
commit
bd18907150
@ -62,15 +62,9 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
$logger = $this->logger instanceof DebugLoggerInterface ? $this->logger : null;
|
$logger = $this->logger instanceof DebugLoggerInterface ? $this->logger : null;
|
||||||
|
|
||||||
$flattenException = FlattenException::create($exception);
|
|
||||||
if ($exception instanceof HttpExceptionInterface) {
|
|
||||||
$flattenException->setStatusCode($exception->getStatusCode());
|
|
||||||
$flattenException->setHeaders($exception->getHeaders());
|
|
||||||
}
|
|
||||||
|
|
||||||
$attributes = array(
|
$attributes = array(
|
||||||
'_controller' => $this->controller,
|
'_controller' => $this->controller,
|
||||||
'exception' => $flattenException,
|
'exception' => FlattenException::create($exception),
|
||||||
'logger' => $logger,
|
'logger' => $logger,
|
||||||
'format' => $request->getRequestFormat(),
|
'format' => $request->getRequestFormat(),
|
||||||
);
|
);
|
||||||
|
@ -36,8 +36,13 @@ class FlattenException
|
|||||||
$e->setMessage($exception->getMessage());
|
$e->setMessage($exception->getMessage());
|
||||||
$e->setCode($exception->getCode());
|
$e->setCode($exception->getCode());
|
||||||
|
|
||||||
|
if ($exception instanceof HttpExceptionInterface) {
|
||||||
|
$statusCode = $exception->getStatusCode();
|
||||||
|
$headers = array_merge($headers, $exception->getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $statusCode) {
|
if (null === $statusCode) {
|
||||||
$statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
|
$statusCode = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
$e->setStatusCode($statusCode);
|
$e->setStatusCode($statusCode);
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\Exception;
|
|||||||
|
|
||||||
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
use Symfony\Component\HttpKernel\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
||||||
|
|
||||||
class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
|
class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -28,6 +29,12 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('404', $flattened->getStatusCode());
|
$this->assertEquals('404', $flattened->getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHeadersForHttpException()
|
||||||
|
{
|
||||||
|
$flattened = FlattenException::create(new MethodNotAllowedHttpException(array('POST')));
|
||||||
|
$this->assertEquals(array('Allow' => 'POST'), $flattened->getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider flattenDataProvider
|
* @dataProvider flattenDataProvider
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user