Better error message on incompatible template file

This commit is contained in:
Andy Miller
2015-08-26 11:20:14 -06:00
parent 03613481a3
commit a19e20e347
4 changed files with 17 additions and 6 deletions

View File

@@ -48,4 +48,5 @@ h6 {
code {
font-weight: bold;
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
}

View File

@@ -16,10 +16,14 @@
<header>
Server Error
</header>
<p>We're sorry! The server has encountered an internal error and was unable to complete your request.
Please contact the system administrator for more information.</p>
<h6>For further details please review your <code>logs/</code> folder, or enable displaying of errors in your system configuration.</h6>
<h6>Error Code: <b><?php echo $code ?></b></h6>
<p>Sorry, something went terribly wrong!</p>
<h3><?php echo $code ?> - <?php echo $message ?></h3>
<h5>For further details please review your <code>logs/</code> folder, or enable displaying of errors in your system configuration.</h5>
</div>
</div>
</body>

View File

@@ -28,6 +28,7 @@ class SimplePageHandler extends Handler
$cssFile = $this->getResource("error.css");
$code = $inspector->getException()->getCode();
$message = $inspector->getException()->getMessage();
if ($inspector->getException() instanceof \ErrorException) {
$code = Misc::translateErrorCode($code);
@@ -36,6 +37,7 @@ class SimplePageHandler extends Handler
$vars = array(
"stylesheet" => file_get_contents($cssFile),
"code" => $code,
"message" => $message,
);
$helper->setVariables($vars);

View File

@@ -4,6 +4,7 @@ namespace Grav\Common\Twig;
use Grav\Common\Grav;
use Grav\Common\Config\Config;
use Grav\Common\Page\Page;
use Grav\Common\Inflector;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
/**
@@ -303,6 +304,7 @@ class Twig
$pages = $this->grav['pages'];
$page = $this->grav['page'];
$content = $page->content();
$config = $this->grav['config'];
$twig_vars = $this->twig_vars;
@@ -325,14 +327,16 @@ class Twig
$output = $this->twig->render($template, $twig_vars);
} catch (\Twig_Error_Loader $e) {
// If loader error, and not .html.twig, try it as fallback
$inflector = new Inflector();
$error_msg = 'The template file for this page: "' . $page->template().'.html'.TWIG_EXT.'" is not provided by the theme: "'. $inflector->titleize($config->get('system.pages.theme')) .'"';
if ($ext != '.html'.TWIG_EXT) {
try {
$output = $this->twig->render($page->template().'.html'.TWIG_EXT, $twig_vars);
} catch (\Twig_Error_Loader $e) {
throw new \RuntimeException($e->getRawMessage(), 404, $e);
throw new \RuntimeException($error_msg, 400, $e);
}
} else {
throw new \RuntimeException($e->getRawMessage(), 404, $e);
throw new \RuntimeException($error_msg, 400, $e);
}
}