/** * @param \Exception $errors * @return Response */ public function handleError(\Exception $errors) { $logger = $this->container['logger']; if (!isset($this->container['response'])) { $response = $this->prepareResponse(); } else { $response = $this->container['response']; } $action_result = ""; if ($this->app->isDebug()) { $logger->error('Error occurred. (This log is debug mode only) ', ['error' => get_class($errors), 'message' => $errors->getMessage()]); $debug_controller = isset($this->container['app.debug_controller']) ? $this->container['app.debug_controller'] : __NAMESPACE__ . '\\Controller\\DebugController'; $controller = $this->app->createController($debug_controller); // FIXME: debug controller method name? $action_result = $this->executeAction([$controller, 'dumpErrors'], ['errors' => $errors], $fire_events = false); } else { $logger->info('Error occurred. ', ['error' => get_class($errors), 'message' => $errors->getMessage()]); list($controller_name, $action_name) = $this->detectErrorAction($errors); $controller = $this->app->createController($controller_name); $action_result = $this->executeAction([$controller, $action_name], ['errors' => $errors], $fire_events = false); } $response->setBody($action_result); return $this->filterResponse($response); }