Skip to content

Commit

Permalink
[HttpKernel] moved exception management logic to its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 17, 2011
1 parent b094806 commit e8b0b48
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Symfony/Component/HttpKernel/HttpKernel.php
Expand Up @@ -58,23 +58,14 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
try {
$response = $this->handleRaw($request, $type);
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if (false === $catch) {
throw $e;
}

// exception
$event = new Event($this, 'core.exception', array('request_type' => $type, 'request' => $request, 'exception' => $e));
$response = $this->dispatcher->notifyUntil($event);
if (!$event->isProcessed()) {
throw $e;
}

$response = $this->filterResponse($response, $request, 'A "core.exception" listener returned a non response object.', $type);
return $this->handleException($e, $request, $type);
}

return $response;
}

/**
Expand Down Expand Up @@ -156,6 +147,26 @@ protected function filterResponse($response, $request, $message, $type)
return $response;
}

/**
* Handles and exception by trying to convert it to a Response.
*
* @param \Exception $e An \Exception instance
* @param Request $request A Request instance
* @param integer $type The type of the request
*
* @return Response A Response instance
*/
protected function handleException(\Exception $e, $request, $type)
{
$event = new Event($this, 'core.exception', array('request_type' => $type, 'request' => $request, 'exception' => $e));
$response = $this->dispatcher->notifyUntil($event);
if (!$event->isProcessed()) {
throw $e;
}

return $this->filterResponse($response, $request, 'A "core.exception" listener returned a non response object.', $type);
}

protected function varToString($var)
{
if (is_object($var)) {
Expand Down

0 comments on commit e8b0b48

Please sign in to comment.