Commit a0274403 authored by Fabien Potencier's avatar Fabien Potencier

simplified the error handler as most of the code has now been migrated to Symfony directly

parent 4091be76
......@@ -13,7 +13,6 @@ namespace Silex;
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler as DebugExceptionHandler;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -27,23 +26,9 @@ class ExceptionHandler implements EventSubscriberInterface
public function onSilexError(GetResponseForErrorEvent $event)
{
$app = $event->getKernel();
$exception = $event->getException();
$code = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500;
$handler = new DebugExceptionHandler($app['debug']);
if ($app['debug']) {
$handler = new DebugExceptionHandler();
$response = new Response($handler->getErrorMessage($exception), $code);
} else {
$title = 'Whoops, looks like something went wrong.';
if (404 == $code) {
$title = 'Sorry, the page you are looking for could not be found.';
}
$response = new Response(sprintf('<!DOCTYPE html><html><head><meta charset="utf-8"><title>%s</title></head><body><h1>%s</h1></body></html>', $title, $title), $code);
}
$event->setResponse($response);
$event->setResponse($handler->createResponse($event->getException()));
}
/**
......
......@@ -50,7 +50,8 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$request = Request::create('/foo');
$response = $app->handle($request);
$this->assertContains('<title>foo exception (500 Internal Server Error)</title>', $response->getContent());
$this->assertContains('foo exception', $response->getContent());
$this->assertEquals(500, $response->getStatusCode());
}
......@@ -72,7 +73,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
$request = Request::create('/foo');
$response = $app->handle($request);
$this->assertContains('<title>No route found for "GET /foo" (500 Internal Server Error)</title>', $response->getContent());
$this->assertContains('No route found for "GET /foo"', $response->getContent());
$this->assertEquals(404, $response->getStatusCode());
}
......
Subproject commit 3a0562757737c0d640b5f7c69efe2fbbaebd4a7c
Subproject commit 14b5f9385023567b59b8f227fc463968a3426a13
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment