/** * Runs the action * * @return string result content */ public function run() { if (($exception = Leaps::$app->getErrorHandler()->exception) === null) { // action has been invoked not from error handler, but by direct route, so we display '404 Not Found' $exception = new HttpException(404, Leaps::t('leaps', 'Page not found.')); } if ($exception instanceof HttpException) { $code = $exception->statusCode; } else { $code = $exception->getCode(); } if ($exception instanceof Exception) { $name = $exception->getName(); } else { $name = $this->defaultName ?: Leaps::t('leaps', 'Error'); } if ($code) { $name .= " (#{$code})"; } if ($exception instanceof UserException) { $message = $exception->getMessage(); } else { $message = $this->defaultMessage ?: Leaps::t('leaps', 'An internal server error occurred.'); } if (Leaps::$app->getRequest()->getIsAjax()) { return "{$name}: {$message}"; } else { return $this->controller->render($this->view ?: $this->id, ['name' => $name, 'message' => $message, 'exception' => $exception]); } }
/** * Converts an exception into an array. * * @param \Exception $exception the exception being converted * @return array the array representation of the exception. */ protected function convertExceptionToArray($exception) { if (!LEAPS_DEBUG && !$exception instanceof UserException && !$exception instanceof HttpException) { $exception = new HttpException(500, 'There was an error at the server.'); } $array = ['name' => $exception instanceof Exception || $exception instanceof ErrorException ? $exception->getName() : 'Exception', 'message' => $exception->getMessage(), 'code' => $exception->getCode()]; if ($exception instanceof HttpException) { $array['status'] = $exception->statusCode; } if (LEAPS_DEBUG) { $array['type'] = get_class($exception); if (!$exception instanceof UserException) { $array['file'] = $exception->getFile(); $array['line'] = $exception->getLine(); $array['stack-trace'] = explode("\n", $exception->getTraceAsString()); if ($exception instanceof \Leaps\Db\Exception) { $array['error-info'] = $exception->errorInfo; } } } if (($prev = $exception->getPrevious()) !== null) { $array['previous'] = $this->convertExceptionToArray($prev); } return $array; }