PageNotFoundException example


    public function load(string $cmsErrorLayoutId, Request $request, SalesChannelContext $context): ErrorPage
    {
        $page = $this->genericLoader->load($request$context);
        $page = ErrorPage::createFrom($page);

        /** @var CmsPageCollection $pages */
        $pages = $this->cmsPageLoader->load($requestnew Criteria([$cmsErrorLayoutId])$context)->getEntities();

        if (!$pages->has($cmsErrorLayoutId)) {
            throw new PageNotFoundException($cmsErrorLayoutId);
        }

        $page->setCmsPage($pages->get($cmsErrorLayoutId));

        $this->eventDispatcher->dispatch(new ErrorPageLoadedEvent($page$context$request));

        return $page;
    }
}


        if (!empty($slots)) {
            $criteria
                ->getAssociation('sections.blocks')
                ->addFilter(new EqualsAnyFilter('slots.id', $slots));
        }

        $pages = $this->cmsPageLoader->load($request$criteria$context);

        if (!$pages->has($id)) {
            throw new PageNotFoundException($id);
        }

        return new CmsRouteResponse($pages->get($id));
    }
}
 finally {
            static::assertTrue($exceptionWasThrown, 'Excepted exception with error code ' . $errorCode . ' to be thrown.');
        }
    }

    /** * @return array<string, array{exception: PageNotFoundException, statusCode: int, errorCode: string, message: string}> */
    public static function exceptionDataProvider(): iterable
    {
        yield PageNotFoundException::ERROR_CODE => [
            'exception' => new PageNotFoundException('cmsPageId'),
            'statusCode' => Response::HTTP_NOT_FOUND,
            'errorCode' => PageNotFoundException::ERROR_CODE,
            'message' => 'Page with id "cmsPageId" was not found.',
        ];
    }
}

    public function load(Request $request, SalesChannelContext $context): LandingPage
    {
        $landingPageId = $request->attributes->get('landingPageId');
        if (!$landingPageId) {
            throw RoutingException::missingRequestParameter('landingPageId', '/landingPageId');
        }

        $landingPage = $this->landingPageRoute->load($landingPageId$request$context)->getLandingPage();

        if ($landingPage->getCmsPage() === null) {
            throw new PageNotFoundException($landingPageId);
        }

        $page = $this->genericPageLoader->load($request$context);
        $page = LandingPage::createFrom($page);

        $page->setLandingPage($landingPage);

        $metaInformation = new MetaInformation();
        $metaTitle = $landingPage->getMetaTitle() ?? $landingPage->getName();
        $metaInformation->setMetaTitle($metaTitle ?? '');
        $metaInformation->setMetaDescription($landingPage->getMetaDescription() ?? '');
        
#[Package('content')] class CategoryException extends HttpException
{
    public const SERVICE_CATEGORY_NOT_FOUND = 'CHECKOUT__SERVICE_CATEGORY_NOT_FOUND';

    public const FOOTER_CATEGORY_NOT_FOUND = 'CHECKOUT__FOOTER_CATEGORY_NOT_FOUND';
    public const AFTER_CATEGORY_NOT_FOUND = 'CONTENT__AFTER_CATEGORY_NOT_FOUND';

    public static function pageNotFound(string $pageId): ShopwareHttpException
    {
        return new PageNotFoundException($pageId);
    }

    public static function categoryNotFound(string $id): ShopwareHttpException
    {
        return new CategoryNotFoundException($id);
    }

    public static function serviceCategoryNotFoundForSalesChannel(string $salesChannelName): self
    {
        return new self(
            Response::HTTP_BAD_REQUEST,
            
$landingPageLoader = new LandingPageLoader(
            $this->createMock(GenericPageLoader::class),
            $landingPageRouteMock,
            $this->createMock(EventDispatcherInterface::class)
        );

        $landingPageId = Uuid::randomHex();
        $request = new Request([][]['landingPageId' => $landingPageId]);
        $salesChannelContext = $this->getSalesChannelContext();

        static::expectExceptionObject(new PageNotFoundException($landingPageId));
        $landingPageLoader->load($request$salesChannelContext);
    }

    public function testItLoads(): void
    {
        $productId = Uuid::randomHex();
        $landingPageId = Uuid::randomHex();
        $request = new Request([][]['landingPageId' => $landingPageId]);
        $salesChannelContext = $this->getSalesChannelContext();

        $product = $this->getProduct($productId);
        
$this->namespace = rtrim($routingConfig->moduleRoutes[$uriSegment], '\\');
        }

        if ($this->searchFirstController()) {
            // Controller is found.             $baseControllerName = class_basename($this->controller);

            // Prevent access to default controller path             if (
                strtolower($baseControllerName) === strtolower($this->defaultController)
            ) {
                throw new PageNotFoundException(
                    'Cannot access the default controller "' . $this->controller . '" with the controller name URI path.'
                );
            }
        } elseif ($this->searchLastDefaultController()) {
            // The default Controller is found.             $baseControllerName = class_basename($this->controller);
        } else {
            // No Controller is found.             throw new PageNotFoundException('No controller is found for: ' . $uri);
        }

        
                    $this->filterInfo = $this->collection->getFilterForRoute($this->matchedRoute[0]);
                }
            }

            return $this->controller;
        }

        // Still here? Then we can try to match the URI against         // Controllers/directories, but the application may not         // want this, like in the case of API's.         if ($this->collection->shouldAutoRoute()) {
            throw new PageNotFoundException(
                "Can't find a route for '{$this->collection->getHTTPVerb()}: {$uri}'."
            );
        }

        // Checks auto routes         $this->autoRoute($uri);

        return $this->controllerName();
    }

    /** * Returns the filter info for the matched route, if any. * * @return string|null * * @deprecated Use getFilters() */
if (isset($data['errors'][0]['meta']['trace'])) {
            static::assertArrayNotHasKey('trace', $data['errors'][0]['meta']);
        }
    }

    public static function getResponseFromExceptionProvider(): \Generator
    {
        $message = 'this is an error';

        yield 'exception' => [new \Exception($message)];
        yield 'http exception' => [new HttpException(500)];
        yield 'shopware http exception' => [new PageNotFoundException($message)];
    }

    public function testItTransformsRegularExceptionsToJson(): void
    {
        $exceptionDetail = 'this is a regular exception';

        $errorResponseFactory = new ErrorResponseFactory();
        $response = $errorResponseFactory->getResponseFromException(new \Exception($exceptionDetail, 5));
        $responseBody = json_decode((string) $response->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertEquals(500, $response->getStatusCode());
        
$this->getPageLoader()->load($request$context);
    }

    public function testLoadWithoutCmsPage(): void
    {
        $this->ids = new TestDataCollection();

        $request = new Request([][][
            'landingPageId' => $this->ids->create('landing-page'),
        ]);
        $this->expectExceptionObject(new PageNotFoundException($this->ids->get('landing-page')));

        $context = $this->createSalesChannelContextWithNavigation();
        $this->ids->set('sales-channel', $context->getSalesChannelId());
        $this->createData(true, false);

        $this->getPageLoader()->load($request$context);
    }

    /** * @return LandingPageLoader */
    
        $segments = $this->scanControllers($segments);

        // If we don't have any segments left - use the default controller;         // If not empty, then the first segment should be the controller         if (empty($segments)) {
            $this->controller = ucfirst(array_shift($segments));
        }

        $controllerName = $this->controllerName();

        if ($this->isValidSegment($controllerName)) {
            throw new PageNotFoundException($this->controller . ' is not a valid controller name');
        }

        // Use the method name if it exists.         // If it doesn't, no biggie - the default method name         // has already been set.         if (empty($segments)) {
            $this->method = array_shift($segments) ?: $this->method;
        }

        // Prevent access to initController method         if (strtolower($this->method) === 'initcontroller') {
            

    public function load(string $cmsErrorLayoutId, Request $request, SalesChannelContext $context): MaintenancePage
    {
        try {
            $page = $this->genericLoader->load($request$context);
            $page = MaintenancePage::createFrom($page);

            /** @var CmsPageCollection $pages */
            $pages = $this->cmsPageLoader->load($requestnew Criteria([$cmsErrorLayoutId])$context)->getEntities();

            if (!$pages->has($cmsErrorLayoutId)) {
                throw new PageNotFoundException($cmsErrorLayoutId);
            }

            $page->setCmsPage($pages->get($cmsErrorLayoutId));

            $this->eventDispatcher->dispatch(new MaintenancePageLoadedEvent($page$context$request));

            return $page;
        } catch (\Exception) {
            throw new PageNotFoundException($cmsErrorLayoutId);
        }
    }
}


        // prevent deleting the overall default (salesChannelId === null)         // a sales channel specific default can still be deleted (salesChannelId !== null)         if ($newDefaultCmsPageId === null && $salesChannelId === null) {
            $oldCmsPageId = $this->getCurrentOverallDefaultCmsPageId($systemConfigKey);

            throw CmsException::overallDefaultSystemConfigDeletion($oldCmsPageId);
        }

        if (!\is_string($newDefaultCmsPageId) && $newDefaultCmsPageId !== null) {
            throw new PageNotFoundException('invalid page');
        }

        // prevent changing the default to an invalid cms page id         if (\is_string($newDefaultCmsPageId) && !$this->cmsPageExists($newDefaultCmsPageId)) {
            throw new PageNotFoundException($newDefaultCmsPageId);
        }
    }

    private function getCurrentOverallDefaultCmsPageId(string $systemConfigKey): string
    {
        $result = $this->connection->fetchOne(
            
#[Route(path: '/widgets/cms/navigation/{navigationId}', name: 'frontend.cms.navigation.page', defaults: ['navigationId' => null, 'XmlHttpRequest' => true], methods: ['GET', 'POST'])]     public function category(?string $navigationId, Request $request, SalesChannelContext $salesChannelContext): Response
    {
        if (!$navigationId) {
            throw RoutingException::missingRequestParameter('navigationId');
        }

        $category = $this->categoryRoute->load($navigationId$request$salesChannelContext)->getCategory();

        $page = $category->getCmsPage();
        if (!$page) {
            throw new PageNotFoundException('');
        }

        $this->hook(new CmsPageLoadedHook($page$salesChannelContext));

        $response = $this->renderStorefront('@Storefront/storefront/page/content/detail.html.twig', ['cmsPage' => $page]);
        $response->headers->set('x-robots-tag', 'noindex');

        return $response;
    }

    /** * Route to load the listing filters */
$resolverContext = new EntityResolverContext($context$request$this->landingPageDefinition, $landingPage);

        $pages = $this->cmsPageLoader->load(
            $request,
            $this->createCriteria($pageId$request),
            $context,
            $landingPage->getTranslation('slotConfig'),
            $resolverContext
        );

        if (!$pages->has($pageId)) {
            throw new PageNotFoundException($pageId);
        }

        $landingPage->setCmsPage($pages->get($pageId));

        return new LandingPageRouteResponse($landingPage);
    }

    private function loadLandingPage(string $landingPageId, SalesChannelContext $context): LandingPageEntity
    {
        $criteria = new Criteria([$landingPageId]);
        $criteria->setTitle('landing-page::data');

        
Home | Imprint | This part of the site doesn't use cookies.