<?php
namespace AdminBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
class ErrorController extends BaseController {
public function show(
\Throwable $exception,
?DebugLoggerInterface $logger,
Request $request
) {
$msg = $exception->getMessage();
if ($exception instanceof NotFoundHttpException) {
$code = $exception->getStatusCode();
$title = 'Page not found';
$msg = "We are sorry this page does not exist.";
} else {
if ($_ENV['APP_ENV'] === 'dev') {
throw $exception;
} else {
$title = 'An Error Occurred.';
$msg = 'Something went wrong.';
$code = 500;
}
}
$route = 'root';
if ($u = $this->getUser()) {
if (
$u->hasRole('ROLE_ADMIN') ||
$u->hasRole('ROLE_OPERATOR') ||
$u->hasRole('ROLE_OPERATOR_ADMIN')
) {
$route = 'sonata_admin_dashboard';
} elseif (
$u->hasRole('ROLE_CLIENT') ||
$u->hasRole('ROLE_COMPANY')
) {
$route = 'client_bounce';
} elseif ($u->hasRole('ROLE_DRIVER')) {
$route = 'driver_bookings';
}
} else {
$uri = $request->server->get('REQUEST_URI');
if (strpos($uri, 'admin/') !== false) {
$route = 'sonata_admin_dashboard';
} else if (strpos($uri, 'client/')) {
$route = 'client_bounce';
} else if (strpos($uri, 'driver/')) {
$route = 'driver_bookings';
}
}
return $this->render('@Admin/Error/error.html.twig', [
'route' => $route,
'title' => $title,
'code' => $code,
'msg' => $msg,
]);
}
}