parent
f1641819ee
commit
5ba7f3cb3b
@ -1,4 +1,4 @@ |
||||
# define your env variables for the test env here |
||||
KERNEL_CLASS='App\Kernel' |
||||
KERNEL_CLASS='Chamilo\Kernel' |
||||
APP_SECRET='s$cretf0rt3st' |
||||
SYMFONY_DEPRECATIONS_HELPER=999999 |
||||
|
||||
@ -1,3 +1,3 @@ |
||||
_errors: |
||||
resource: '@TwigBundle/Resources/config/routing/errors.xml' |
||||
resource: '@FrameworkBundle/Resources/config/routing/errors.xml' |
||||
prefix: /_error |
||||
|
||||
@ -0,0 +1,83 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Controller; |
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
||||
use Symfony\Component\ErrorHandler\Exception\FlattenException; |
||||
use Symfony\Component\HttpFoundation\Request; |
||||
use Symfony\Component\HttpKernel\Exception\HttpException; |
||||
use Symfony\Component\Routing\Annotation\Route; |
||||
|
||||
class ExceptionController extends AbstractController |
||||
{ |
||||
public function showAction(FlattenException $exception) |
||||
{ |
||||
if ('dev' === $this->getParameter('app_env')) { |
||||
throw new HttpException($exception->getCode(), $exception->getMessage()); |
||||
} |
||||
|
||||
$showException = true; |
||||
$name = $showException ? 'exception' : 'error'; |
||||
$code = $exception->getCode(); |
||||
$format = 'html'; |
||||
$loader = $this->container->get('twig')->getLoader(); |
||||
// when not in debug, try to find a template for the specific HTTP status code and format |
||||
if (!$showException) { |
||||
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format); |
||||
if ($loader->exists($template)) { |
||||
return $template; |
||||
} |
||||
} |
||||
|
||||
// try to find a template for the given format |
||||
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); |
||||
if ($loader->exists($template)) { |
||||
return $template; |
||||
} |
||||
|
||||
// default to a generic HTML exception |
||||
//$request->setRequestFormat('html'); |
||||
$template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); |
||||
|
||||
return $this->render($template, ['exception' => $exception]); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/error") |
||||
*/ |
||||
public function errorAction(Request $request) |
||||
{ |
||||
$message = $request->getSession()->get('error_message', ''); |
||||
$exception = new FlattenException(); |
||||
$exception->setCode(500); |
||||
|
||||
$exception->setMessage($message); |
||||
|
||||
$showException = true; |
||||
$name = $showException ? 'exception' : 'error'; |
||||
$code = $exception->getCode(); |
||||
$format = 'html'; |
||||
$loader = $this->container->get('twig')->getLoader(); |
||||
// when not in debug, try to find a template for the specific HTTP status code and format |
||||
if (!$showException) { |
||||
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format); |
||||
if ($loader->exists($template)) { |
||||
return $template; |
||||
} |
||||
} |
||||
|
||||
// try to find a template for the given format |
||||
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); |
||||
if ($loader->exists($template)) { |
||||
return $template; |
||||
} |
||||
|
||||
// default to a generic HTML exception |
||||
//$request->setRequestFormat('html'); |
||||
$template = sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); |
||||
|
||||
return $this->render($template, ['exception' => $exception]); |
||||
} |
||||
} |
||||
@ -1,54 +0,0 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ThemeBundle\Controller; |
||||
|
||||
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; |
||||
use Symfony\Component\HttpFoundation\Request; |
||||
use Symfony\Component\Templating\TemplateReference; |
||||
|
||||
/** |
||||
* Class ExceptionController. |
||||
*/ |
||||
class ExceptionController extends BaseExceptionController |
||||
{ |
||||
/** |
||||
* @param string $format |
||||
* @param int $code |
||||
* @param bool $showException |
||||
* |
||||
* @return TemplateReference |
||||
*/ |
||||
protected function findTemplate(Request $request, $format, $code, $showException) |
||||
{ |
||||
// Only show custom error when APP_DEBUG = 0 |
||||
if ($showException) { |
||||
return parent::findTemplate($request, $format, $code, $showException); |
||||
} |
||||
|
||||
$name = $showException ? 'exception' : 'error'; |
||||
if ($showException && 'html' == $format) { |
||||
$name = 'exception_full'; |
||||
} |
||||
|
||||
// when not in debug, try to find a template for the specific HTTP status code and format |
||||
if (!$showException) { |
||||
$template = sprintf('@ChamiloTheme/Exception/%s%s.%s.twig', $name, $code, $format); |
||||
if ($this->templateExists($template)) { |
||||
return $template; |
||||
} |
||||
} |
||||
|
||||
// try to find a template for the given format |
||||
$template = sprintf('@ChamiloTheme/Exception/%s.%s.twig', $name, $format); |
||||
if ($this->templateExists($template)) { |
||||
return $template; |
||||
} |
||||
|
||||
// default to a generic HTML exception |
||||
$request->setRequestFormat('html'); |
||||
|
||||
return sprintf('@ChamiloTheme/Exception/%s.html.twig', $showException ? 'exception_full' : $name); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue