<?php
namespace Nellapp\Bundle\SDKBundle\Twig\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Twig\Environment;
class ErrorController
{
private Environment $twig;
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
public function show(\Throwable $exception): Response
{
$statusCode = $exception instanceof HttpExceptionInterface
? $exception->getStatusCode()
: 500;
$template = "@NellappSDK/Exception/error{$statusCode}.html.twig";
if (!$this->twig->getLoader()->exists($template)) {
$template = "@NellappSDK/Exception/error.html.twig";
}
return new Response(
$this->twig->render($template, [
'exception' => $exception,
'status_code' => $statusCode,
]),
$statusCode
);
}
}