<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ErrorController extends AbstractController
{
function show(\Throwable $exception, $logger, Request $request) {
if ($exception instanceof NotFoundHttpException) {
return $this->redirectToRoute('home');
}
$requestUri = $request->getRequestUri();
if (strpos($requestUri, '/api')) {
$traceOut = [];
$trace = $exception->getTrace();
foreach ($trace as $tr) {
$traceOut[] = [
'file' => $tr['file'],
'line' => $tr['line']
];
}
$resp = [
'success' => false,
'error' => $exception->getMessage(),
'trace' => $traceOut
];
return $this->json($resp);
}
return $this->render('error.html.twig', [
'error' => $exception
]);
}
}