Skip to content

Commit

Permalink
error.html.twig Exception Subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushwebkul committed Oct 7, 2019
1 parent ba8951e commit d1a414b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
14 changes: 3 additions & 11 deletions src/EventListener/ExceptionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class ExceptionSubscriber implements EventSubscriberInterface
{
private $container;
private $twig;

public function __construct(ContainerInterface $container, Environment $twig)
{
Expand All @@ -34,34 +35,25 @@ public static function getSubscribedEvents()
public function onKernelException(ExceptionEvent $event)
{
$exception = $event->getException();

if ($this->container->get('kernel')->getEnvironment() === 'prod') {
if ($exception->getCode() == 403) {
$notFoundTemplate = $this->twig->render('errors/error.html.twig', [
'code' => 403,
'message' => 'Access Forbidden',
'description' => 'You are not authorized to access this page.',
]);

$notFoundResponse = new Response($notFoundTemplate, 403);
return;
} elseif ($exception instanceof NotFoundHttpException) {
$notFoundTemplate = $this->twig->render('errors/error.html.twig', [
'code' => 404,
'message' => 'Page not Found',
'description' => 'We were not able to find the page you are looking for.',
]);

$notFoundResponse = new Response($notFoundTemplate, 404);
} else {
$notFoundTemplate = $this->twig->render('errors/error.html.twig', [
'message' => 'Internal Server Error',
'code' => 500,
'description' => 'Something has gone wrong on the server. Please try again later.',
]);

$notFoundResponse = new Response($notFoundTemplate, 500);
}

$event->setResponse($notFoundResponse);
}
}
Expand Down
2 changes: 0 additions & 2 deletions templates/errors/error.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
<p>Few of the links which may help you to get back on the track -</p>

<ul>
<li><a href="{{ path('helpdesk_member_dashboard') }}">Home</a></li>
<li><a href="https://support.uvdesk.com">Support</a></li>
<li><a href="{{ path('helpdesk_member_handle_login') }}">Sign In</a></li>
<li><a href="{{ path('helpdesk_customer_create_ticket') }}">Contact Team UVdesk</a></li>
</ul>
</div>
Expand Down

0 comments on commit d1a414b

Please sign in to comment.