From 65ff838dd97329c2ec75cef9a5b742eab86c8e6e Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 16 Jul 2025 15:50:45 +0200 Subject: [PATCH] handle error --- src/Controller/UserController.php | 3 +++ .../bundles/TwigBundle/Exception/error404.html.twig | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 templates/bundles/TwigBundle/Exception/error404.html.twig diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 0dadb33..d2bf263 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -38,6 +38,9 @@ class UserController extends AbstractController if ($this->isGranted('ROLE_SUDALYS_ADMIN')) { $userId = $request->attributes->get('id'); $user = $entityManager->getRepository(User::class)->find($userId); + if(!$user) { + throw $this->createNotFoundException('User not found'); + } $userOrganizations = $this->userOrganizationService->getUserOrganizations($user); } return $this->render('user/profile.html.twig', [ diff --git a/templates/bundles/TwigBundle/Exception/error404.html.twig b/templates/bundles/TwigBundle/Exception/error404.html.twig new file mode 100644 index 0000000..7597d0e --- /dev/null +++ b/templates/bundles/TwigBundle/Exception/error404.html.twig @@ -0,0 +1,11 @@ +{% extends 'base.html.twig' %} + +{% block title %}Page Not Found (404){% endblock %} + +{% block body %} +
+

Oops! La page n'existe pas (404)

+

La page que vous cherchez n'existe pas.

+ Retour à l'accueil +
+{% endblock %} \ No newline at end of file