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'])]