From 80effd62330702cfc4c3c8648043ff881ed1823a Mon Sep 17 00:00:00 2001 From: Orka Arnest CRUZE Date: Wed, 18 Sep 2024 15:16:00 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20affiche=20page=20404=20si=20l'url=20de?= =?UTF-8?q?=20page=20demand=C3=A9e=20poss=C3=A8de=20un=20datastoreId=20qui?= =?UTF-8?q?=20n'existe=20pas=20ou=20l'utilisateur=20n'en=20est=20pas=20mem?= =?UTF-8?q?bre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/components/Layout/DatastoreLayout.tsx | 9 ++++++++- src/Controller/Entrepot/DatastoreController.php | 16 ++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/assets/components/Layout/DatastoreLayout.tsx b/assets/components/Layout/DatastoreLayout.tsx index 14c9aa88..ce7e7b33 100644 --- a/assets/components/Layout/DatastoreLayout.tsx +++ b/assets/components/Layout/DatastoreLayout.tsx @@ -2,9 +2,12 @@ import { BreadcrumbProps } from "@codegouvfr/react-dsfr/Breadcrumb"; import { useQuery } from "@tanstack/react-query"; import { FC, PropsWithChildren, memo, useMemo } from "react"; +import { Datastore } from "../../@types/app"; import { datastoreNavItems } from "../../config/datastoreNavItems"; import api from "../../entrepot/api"; import RQKeys from "../../modules/entrepot/RQKeys"; +import { CartesApiException } from "../../modules/jsonFetch"; +import PageNotFound from "../../pages/error/PageNotFound"; import AppLayout from "./AppLayout"; type DatastoreLayoutProps = { @@ -13,7 +16,7 @@ type DatastoreLayoutProps = { customBreadcrumbProps?: BreadcrumbProps; }; const DatastoreLayout: FC> = ({ datastoreId, documentTitle, customBreadcrumbProps, children }) => { - const datastoreQuery = useQuery({ + const datastoreQuery = useQuery({ queryKey: RQKeys.datastore(datastoreId), queryFn: ({ signal }) => api.datastore.get(datastoreId, { signal }), staleTime: 3600000, @@ -21,6 +24,10 @@ const DatastoreLayout: FC> = ({ datastor const navItems = useMemo(() => datastoreNavItems(datastoreQuery.data), [datastoreQuery.data]); + if (datastoreQuery?.error?.code === 404 || datastoreQuery.failureReason?.code === 404) { + return ; + } + return ( {children} diff --git a/src/Controller/Entrepot/DatastoreController.php b/src/Controller/Entrepot/DatastoreController.php index 3237d818..683320ca 100644 --- a/src/Controller/Entrepot/DatastoreController.php +++ b/src/Controller/Entrepot/DatastoreController.php @@ -33,13 +33,17 @@ public function __construct( #[Route('/{datastoreId}', name: 'get', methods: ['GET'])] public function getDatastore(string $datastoreId): JsonResponse { - $datastore = $this->datastoreApiService->get($datastoreId); - $datastore['is_sandbox'] = $this->sandboxService->isSandboxDatastore($datastore['_id']); - if (true === $datastore['is_sandbox']) { - $datastore['name'] = 'Découverte'; - } + try { + $datastore = $this->datastoreApiService->get($datastoreId); + $datastore['is_sandbox'] = $this->sandboxService->isSandboxDatastore($datastore['_id']); + if (true === $datastore['is_sandbox']) { + $datastore['name'] = 'Découverte'; + } - return $this->json($datastore); + return $this->json($datastore); + } catch (ApiException $ex) { + throw new CartesApiException($ex->getMessage(), $ex->getStatusCode(), $ex->getDetails(), $ex); + } } #[Route('/{datastoreId}/endpoints', name: 'get_endpoints', methods: ['GET'])]