ProviderException example

$responses[] = $this->uploadTranslations($fileId$domain$content$catalogue->getLocale());
                }
            }
        }

        foreach ($responses as $response) {
            if (200 !== $statusCode = $response->getStatusCode()) {
                $this->logger->error(sprintf('Unable to upload translations to Crowdin: "%s".', $response->getContent(false)));

                if (500 <= $statusCode) {
                    throw new ProviderException('Unable to upload translations to Crowdin.', $response);
                }
            }
        }
    }

    public function read(array $domains, array $locales): TranslatorBag
    {
        $fileList = $this->getFileList();

        $translatorBag = new TranslatorBag();
        $responses = [];

        

    catch (TransferException $e) {
      if (isset($stored['data'])) {
        // Use the stale data to fall back gracefully, but warn site         // administrators that we used stale data.         $this->logger->warning('Remote oEmbed providers could not be retrieved due to error: @error. Using previously stored data. This may contain out of date information.', [
          '@error' => $e->getMessage(),
        ]);
        return $stored['data'];
      }
      // We have no previous data and the request failed.       throw new ProviderException("Could not retrieve the oEmbed provider database from $this->providersUrl", NULL, $e);
    }

    $providers = Json::decode((string) $response->getBody());

    if (!is_array($providers) || empty($providers)) {
      if (isset($stored['data'])) {
        // Use the stale data to fall back gracefully, but as above, warn site         // administrators that we used stale data.         $this->logger->warning('Remote oEmbed providers database returned invalid or empty list. Using previously stored data. This may contain out of date information.');
        return $stored['data'];
      }
      

  public function __construct($name$url, array $endpoints) {
    $this->name = $name;

    if (!UrlHelper::isValid($url, TRUE) || !UrlHelper::isExternal($url)) {
      throw new ProviderException('Provider @name does not define a valid external URL.', $this);
    }
    $this->url = $url;

    try {
      foreach ($endpoints as $endpoint) {
        $endpoint += ['formats' => [], 'schemes' => [], 'discovery' => FALSE];
        $this->endpoints[] = new Endpoint($endpoint['url']$this$endpoint['schemes']$endpoint['formats']$endpoint['discovery']);
      }
    }
    catch (\InvalidArgumentException $e) {
      // Just skip all the invalid endpoints.
$pagination = $response->getHeaders()['pagination'][0] ?? '{}';
            $page = json_decode($pagination, true)['next_page'] ?? null;
        } while (null !== $page);
    }

    private function throwProviderException(int $statusCode, ResponseInterface $response, string $message): void
    {
        $headers = $response->getHeaders(false);

        throw match (true) {
            429 === $statusCode => new ProviderException(sprintf('Rate limit exceeded (%s). please wait %s seconds.',
                $headers['x-rate-limit-limit'][0],
                $headers['x-rate-limit-reset'][0]
            )$response),
            $statusCode <= 500 => new ProviderException($message$response),
            default => new ProviderException('Provider server error.', $response),
        };
    }
}
$catalogue->setCatalogueMetadata($key$value$domain);
                    }

                    $translatorBag->addCatalogue($catalogue);

                    continue;
                }

                $responseContent = $response->getContent(false);

                if (200 !== $response->getStatusCode()) {
                    throw new ProviderException('Unable to read the Loco response: '.$responseContent$response);
                }

                $locoCatalogue = $this->loader->load($responseContent$locale$domain);
                $catalogue = new MessageCatalogue($locale);

                foreach ($locoCatalogue->all($domain) as $key => $message) {
                    $catalogue->set($this->retrieveKeyFromId($key$domain)$message$domain);
                }

                if ($previousCatalogue instanceof CatalogueMetadataAwareInterface) {
                    foreach ($previousCatalogue->getCatalogueMetadata('', $domain) ?? [] as $key => $value) {
                        
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Exception\ProviderException;
use Symfony\Contracts\HttpClient\ResponseInterface;

class ProviderExceptionTest extends TestCase
{
    public function testExceptionWithDebugMessage()
    {
        $mock = $this->createMock(ResponseInterface::class);
        $mock->method('getInfo')->willReturn('debug');

        $exception = new ProviderException('Exception message', $mock, 503);

        self::assertInstanceOf(ProviderException::class$exception);
    }

    public function testExceptionWithNullAsDebugMessage()
    {
        $mock = $this->createMock(ResponseInterface::class);
        $mock->method('getInfo')->willReturn(null);

        $exception = new ProviderException('Exception message', $mock, 503);

        
continue;
            }

            $keysIds += $this->getKeysIds($keysToDelete$domain);
        }

        $response = $this->client->request('DELETE', 'keys', [
            'json' => ['keys' => array_values($keysIds)],
        ]);

        if (200 !== $response->getStatusCode()) {
            throw new ProviderException(sprintf('Unable to delete keys from Lokalise: "%s".', $response->getContent(false))$response);
        }
    }

    /** * @see https://app.lokalise.com/api2docs/curl/#transition-download-files-post */
    private function exportFiles(array $locales, array $domains): array
    {
        $response = $this->client->request('POST', 'files/export', [
            'json' => [
                'format' => 'symfony_xliff',
                
Home | Imprint | This part of the site doesn't use cookies.