StoreApiException example


        $shopwareId = $request->request->get('shopwareId');
        $password = $request->request->get('password');

        if (!\is_string($shopwareId) || !\is_string($password)) {
            throw new StoreInvalidCredentialsException();
        }

        try {
            $this->storeClient->loginWithShopwareId($shopwareId$password$context);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        return new JsonResponse();
    }

    #[Route(path: '/api/_action/store/checklogin', name: 'api.custom.store.checklogin', methods: ['POST'])]     public function checkLogin(Context $context): Response
    {
        try {
            // Throws StoreTokenMissingException if no token is present             $this->getUserStoreToken($context);

            
private readonly EntityRepository $pluginRepo,
        private readonly EntityRepository $appRepo,
    ) {
    }

    #[Route(path: '/api/_action/store/frw/start', name: 'api.custom.store.frw.start', methods: ['POST'])]     public function frwStart(Context $context): JsonResponse
    {
        try {
            $this->frwService->startFrw($context);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        return new JsonResponse();
    }

    #[Route(path: '/api/_action/store/language-plugins', name: 'api.custom.store.language-plugins', methods: ['GET'])]     public function getLanguagePluginList(Context $context): JsonResponse
    {
        /** @var PluginCollection $plugins */
        $plugins = $this->pluginRepo->search(new Criteria()$context)->getEntities();
        /** @var AppCollection $apps */
        
$pluginName = (string) $input->getOption('pluginName');
        $user = $input->getOption('user');

        $context = $this->getUserContextFromInput($user$context);

        $this->validatePluginIsNotManagedByComposer($pluginName$context);

        try {
            $data = $this->storeClient->getDownloadDataForPlugin($pluginName$context);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        $this->pluginManagementService->downloadStorePlugin($data$context);

        try {
            $plugin = $this->getPluginFromInput($pluginName$context);

            if ($plugin->getUpgradeVersion()) {
                $this->pluginLifecycleService->updatePlugin($plugin$context);
            }
        } catch (PluginNotFoundException) {
            

    public function testGetErrorCode(): void
    {
        $clientException = new ClientException(
            'message',
            new Request('GET', 'https://example.com'),
            new \GuzzleHttp\Psr7\Response()
        );

        static::assertSame(
            'FRAMEWORK__STORE_ERROR',
            (new StoreApiException($clientException))->getErrorCode()
        );
    }

    public function testGetStatusCode(): void
    {
        $clientException = new ClientException(
            'message',
            new Request('GET', 'https://example.com'),
            new \GuzzleHttp\Psr7\Response()
        );

        


        $userContext = new Context(new AdminApiSource($userId));

        if ($shopwareId === null || $password === null) {
            throw new StoreInvalidCredentialsException();
        }

        try {
            $this->storeClient->loginWithShopwareId($shopwareId$password$userContext);
        } catch (ClientException $exception) {
            throw new StoreApiException($exception);
        }

        $io->success('Successfully logged in.');

        return (int) Command::SUCCESS;
    }
}
if ($plugin !== null && $plugin->getManagedByComposer() && !str_starts_with($plugin->getPath() ?? '', $this->relativePluginDir)) {
            if (Feature::isActive('v6.6.0.0')) {
                throw StoreException::cannotDeleteManaged($plugin->getName());
            }

            throw new CanNotDownloadPluginManagedByComposerException('can not download plugins managed by composer from store api');
        }

        try {
            $data = $this->storeClient->getDownloadDataForPlugin($technicalName$context);
        } catch (ClientException $e) {
            throw new StoreApiException($e);
        }

        $this->pluginManagementService->downloadStorePlugin($data$context);

        return $data;
    }
}
public function listMyExtensions(ExtensionCollection $extensions, Context $context): ExtensionCollection
    {
        try {
            $payload = ['plugins' => array_map(fn (ExtensionStruct $e) => [
                'name' => $e->getName(),
                'version' => $e->getVersion(),
            ]$extensions->getElements())];

            $response = $this->fetchLicenses($payload$context);
        } catch (ClientException $e) {
            throw new StoreApiException($e);
        }

        $body = \json_decode($response->getBody()->getContents(), true, flags: \JSON_THROW_ON_ERROR);

        $myExtensions = new ExtensionCollection();

        foreach ($body as $item) {
            $extension = $this->extensionLoader->loadFromArray($context$item['extension']);
            $extension->setSource(ExtensionStruct::SOURCE_STORE);
            if (isset($item['license'])) {
                $extension->setStoreLicense(LicenseStruct::fromArray($item['license']));
            }
Home | Imprint | This part of the site doesn't use cookies.