/**
* Handles a Request to convert it to a Response.
*
* When $catch is true, the implementation must catch all exceptions
* and do its best to convert them to a Response instance.
*
* @param Request $request A Request instance
* @param int $type The type of the request
* (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
* @param bool $catch Whether to catch exceptions or not
*
* @return Response A Response instance
*
* @throws \Exception When an Exception occurs during processing
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
try {
$match = $this->routeMatch;
if (!$match) {
$match = $this->router->match($request->getPathInfo());
}
if ($match) {
list($module, $controller, $action) = $this->processRoute($match);
$request->attributes->add(['_module' => $module, '_controller' => $controller, '_action' => $action]);
$response = $this->dispatcher->dispatch($match['target'], $match['params']);
} else {
$response = $this->dispatcher->dispatch('Home#error', ['message' => 'Halaman tidak ditemukan: ' . $request->getPathInfo()]);
$response->setStatusCode(Response::HTTP_NOT_FOUND);
}
} catch (HttpException $e) {
if (!$catch) {
throw $e;
}
$response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
$response->setStatusCode($e->getStatusCode());
} catch (Exception $e) {
if (!$catch) {
throw $e;
}
$response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
}
//$response->setMaxAge(300);
return $response;
}