allow vendord
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m3s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 32s
Build, Push and Deploy / deploy-production (push) Has been skipped
Build, Push and Deploy / cleanup (push) Successful in 1s
This commit is contained in:
71
vendor/kreait/firebase-php/src/Firebase/Exception/RemoteConfigApiExceptionConverter.php
vendored
Normal file
71
vendor/kreait/firebase-php/src/Firebase/Exception/RemoteConfigApiExceptionConverter.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kreait\Firebase\Exception;
|
||||
|
||||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\ApiConnectionFailed;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\OperationAborted;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\PermissionDenied;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\RemoteConfigError;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\ValidationFailed;
|
||||
use Kreait\Firebase\Exception\RemoteConfig\VersionMismatch;
|
||||
use Kreait\Firebase\Http\ErrorResponseParser;
|
||||
use Throwable;
|
||||
|
||||
use function mb_stripos;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class RemoteConfigApiExceptionConverter
|
||||
{
|
||||
public function __construct(private readonly ErrorResponseParser $responseParser)
|
||||
{
|
||||
}
|
||||
|
||||
public function convertException(Throwable $exception): RemoteConfigException
|
||||
{
|
||||
if ($exception instanceof RequestException) {
|
||||
return $this->convertGuzzleRequestException($exception);
|
||||
}
|
||||
|
||||
if ($exception instanceof ConnectException) {
|
||||
return new ApiConnectionFailed('Unable to connect to the API: '.$exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
|
||||
return new RemoteConfigError($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
|
||||
private function convertGuzzleRequestException(RequestException $e): RemoteConfigException
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
$response = $e->getResponse();
|
||||
|
||||
if ($response !== null) {
|
||||
$message = $this->responseParser->getErrorReasonFromResponse($response);
|
||||
$code = $response->getStatusCode();
|
||||
}
|
||||
|
||||
if (mb_stripos($message, 'permission_denied') !== false) {
|
||||
return new PermissionDenied($message, $code, $e);
|
||||
}
|
||||
|
||||
if (mb_stripos($message, 'aborted') !== false) {
|
||||
return new OperationAborted($message, $code, $e);
|
||||
}
|
||||
|
||||
if (mb_stripos($message, 'version_mismatch') !== false) {
|
||||
return new VersionMismatch($message, $code, $e);
|
||||
}
|
||||
|
||||
if (mb_stripos($message, 'validation_error') !== false) {
|
||||
return new ValidationFailed($message, $code, $e);
|
||||
}
|
||||
|
||||
return new RemoteConfigError($message, $code, $e);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user