unauthorized example

if (!$request->attributes->get('auth_required', true)) {
            return;
        }

        if (!$this->isRequestScoped($request, StoreApiRouteScope::class)) {
            return;
        }

        $accessKey = $request->headers->get(PlatformRequest::HEADER_ACCESS_KEY);
        if (!$accessKey) {
            throw ApiException::unauthorized(
                'header',
                sprintf('Header "%s" is required.', PlatformRequest::HEADER_ACCESS_KEY)
            );
        }

        $origin = AccessKeyHelper::getOrigin($accessKey);
        if ($origin !== 'sales-channel') {
            throw ApiException::salesChannelNotFound();
        }

        $salesChannelData = $this->getSalesChannelData($accessKey);

        
public function testMethodNotAllowed(): void
    {
        $exception = ApiException::methodNotAllowed(['GET'], 'Get only');

        static::assertInstanceOf(MethodNotAllowedHttpException::class$exception);
        static::assertEquals('Get only', $exception->getMessage());
    }

    public function testUnauthorized(): void
    {
        $exception = ApiException::unauthorized('challenge', 'Message');

        static::assertInstanceOf(UnauthorizedHttpException::class$exception);
        static::assertEquals('Message', $exception->getMessage());
    }

    public function testNoEntityCloned(): void
    {
        $exception = ApiException::noEntityCloned('order', '1234');

        static::assertInstanceOf(NoEntityClonedException::class$exception);
        static::assertEquals('Could not clone entity order with id 1234.', $exception->getMessage());
    }
Home | Imprint | This part of the site doesn't use cookies.