Skip to content

Commit

Permalink
Misc. code style fixes from pull request uvdesk#203
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay kumar committed Oct 3, 2019
1 parent ebbfc9d commit 0829537
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 119 deletions.
99 changes: 53 additions & 46 deletions src/EventListener/ExceptionSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,67 @@

namespace App\EventListener;

use Twig\Environment;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig\Environment;

class ExceptionSubscriber implements EventSubscriberInterface
{
private $container;

public function __construct(ContainerInterface $container, Environment $twig) {
$this->container = $container;
$this->twig = $twig;
}

public static function getSubscribedEvents() {
return [
KernelEvents::EXCEPTION => [
['onKernelException', 10]
]
]
;
}

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);
} 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);
}
}
private $container;

public function __construct(ContainerInterface $container, Environment $twig)
{
$this->twig = $twig;
$this->container = $container;
}

public static function getSubscribedEvents()
{
return [
KernelEvents::EXCEPTION => [
['onKernelException', 10]
]
];
}

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);
} 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);
}
}
}
141 changes: 68 additions & 73 deletions templates/errors/error.html.twig
Original file line number Diff line number Diff line change
@@ -1,83 +1,78 @@
<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML1.0Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<head>
<meta http-equiv="Content-Type" content="text/html;" charset="UTF-8" />
<meta name="robots" content="INDEX,FOLLOW" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{ code }} - {{ message }}</title>
<link rel="canonical" href="{{ path('helpdesk_knowledgebase') }}">
<link href="https://cdn.uvdesk.com/uvdesk/css/main.css" type="text/css" rel="stylesheet" media="all" />
<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}" />

<style>
.uv-logo {
height: 70px;
display: table-cell;
}
<meta http-equiv="Content-Type" content="text/html;" charset="UTF-8"/>
<meta name="robots" content="INDEX,FOLLOW"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>
{{ code }} - {{ message }}
</title>
.uv-logo img {
height: 50px;
}
<link rel="canonical" href="{{ path('helpdesk_knowledgebase') }}">
<link href="https://cdn.uvdesk.com/uvdesk/css/main.css" type="text/css" rel="stylesheet" media="all" />
<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}"/>
</head>
.uv-loader-view {
display: none;
}
</style>
</head>

<body class="">
<div class="uv-loader-view" id="uv-def-loader">
<div class="uv-loader">
<span></span>
<span></span>
<span></span>
</div>
</div>

<body class=" ">
<div class="uv-loader-view" id="uv-def-loader">
<div class="uv-loader">
<span></span>
<span></span>
<span></span>
</div>
</div>
<!-- Notifications Block -->
<div class="uv-notifications-wrapper">
<noscript>
<div class="uv-notification page-load uv-error">
<p>Your browser does not support JavaScript or You disabled JavaScript, Please enable those !</p>
</div>
</noscript>
</div>
<!-- //Notifications Block -->

<!-- Notifications Block -->
<div class="uv-notifications-wrapper">
<noscript>
<div class="uv-notification page-load uv-error">
<p>Your browser does not support JavaScript or You disabled JavaScript, Please enable those !</p>
</div>
<style>
.uv-loader-view {
display: none;
}
</style>
</noscript>
</div>
<!-- //Notifications Block -->
<div class="uv-box-server-error">
<div class="uv-box-server-error-lt">
<a class="uv-logo" href="/en/member/dashboard">
<img src="{{ asset('bundles/uvdeskcoreframework/images/uvdesk-logo.svg') }}" title="UVDesk">
</a>

<style>
.uv-logo {
height: 70px;
display: table-cell;
}
.uv-logo img {
height: 50px;
}
.uv-loader-view {
display: none;
}
</style>
<div class="uv-box-server-error">
<div class="uv-box-server-error-lt">
<a class="uv-logo" href="/en/member/dashboard">
<img src="{{ asset('bundles/uvdeskcoreframework/images/uvdesk-logo.svg') }}" title="UVDesk">
</a>
<div class="uv-box-block">
<p class="uv-error-title">
<span>{{ code }}</span>- {{ message}}
<p>{{ description }}</p>
</p>
</p>
</div>
<div class="uv-box-block">
<p class="uv-error-title">
<span>{{ code }}</span>- {{ message}}
<p>{{ description }}</p>
</p>
</div>

<div class="uv-box-block">
<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>
</div>
<div class="uv-box-server-error-rt">
{% set imageUrl = 'bundles/uvdeskcoreframework/images/' ~ code ~ '.png' %}
<img class="error-grooves" src="{{ asset(imageUrl) }}" alt="{{ code }}"/>
</div>
</body>
</html>
<div class="uv-box-block">
<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>
</div>

<div class="uv-box-server-error-rt">
{% set imageUrl = 'bundles/uvdeskcoreframework/images/' ~ code ~ '.png' %}
<img class="error-grooves" src="{{ asset(imageUrl) }}" alt="{{ code }}" />
</div>
</div>
</body>
</html>

0 comments on commit 0829537

Please sign in to comment.