ldc-arcadia-genesis-php-client/src/Exception/ApiErrorException.php
Jérémy Munsch 9c47b9cd66
refactor: rename namespace from ArcadiaGenesisPhpClient to ArcadiaApiPhpClient
This change updates the namespace across multiple files to reflect the new naming convention.
2026-09-11 16:55:12 +02:00

40 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Uwil\ArcadiaApiPhpClient\Exception;
use Uwil\ArcadiaApiPhpClient\Enum\ArcadiaGenesisApiErrorCode;
class ApiErrorException extends \DomainException implements ArcadiaGenesisApiException
{
public readonly ArcadiaGenesisApiErrorCode $apiError;
public function __construct(ArcadiaGenesisApiErrorCode $apiError, ?\Throwable $previous = null)
{
$this->apiError = $apiError;
parent::__construct(
$apiError->description(),
$apiError->httpStatusCode(),
$previous
);
}
/**
* @param array<string,mixed> $error
*/
public static function fromResponseError(array $error): self
{
// FIXME: Patch degueu en attendant une correction de leur part.
// * Si l'api retourne de multiples erreurs, ce qu'elle n'est pas sensée faire alors on prend la derniere du tableau.
if (count($error) > 1 && is_int(array_keys($error)[0] ?? null)) {
$error = array_pop($error);
}
$code = ArcadiaGenesisApiErrorCode::tryFrom($error['code']) ?? ArcadiaGenesisApiErrorCode::UNKNOWN;
return new self($code);
}
}