src/Controller/ErrorController.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  6. class ErrorController extends AbstractController
  7. {
  8.     function show(\Throwable $exception$loggerRequest $request) {
  9.         if ($exception instanceof NotFoundHttpException) {
  10.             return $this->redirectToRoute('home');
  11.         }
  12.         $requestUri $request->getRequestUri();
  13.         if (strpos($requestUri'/api')) {
  14.             $traceOut = [];
  15.             $trace $exception->getTrace();
  16.             foreach ($trace as $tr) {
  17.                 $traceOut[] = [
  18.                     'file' => $tr['file'],
  19.                     'line' => $tr['line']
  20.                 ];
  21.             }
  22.             $resp = [
  23.                 'success' => false,
  24.                 'error' => $exception->getMessage(),
  25.                 'trace' => $traceOut
  26.             ];
  27.             return $this->json($resp);
  28.         }
  29.         return $this->render('error.html.twig', [
  30.             'error' => $exception
  31.         ]);
  32.     }
  33. }