Error pages

Follow Symfony documentation on error page customization

Edit config/package/framework.yaml and define an error_controller

# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
    ...

    error_controller: App\Controller\BlogController::errorAction

Add method in controller

// src/Controller/BlogController.php

public function errorAction(\Throwable $exception)
{
  $code = $exception->getCode();

  if( $code == 503 )
    $response = $this->render( 'maintenance.html.twig' );
  else if( $code == 404 )
    $response = $this->render( '404.html.twig' );
  else
    $response = $this->render( '500.html.twig', ['exception'=>$exception] );

  $response->setStatusCode($code?:500);

  return $response;
}

Last updated