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:
54
vendor/kreait/firebase-php/src/Firebase/Exception/AppCheckApiExceptionConverter.php
vendored
Normal file
54
vendor/kreait/firebase-php/src/Firebase/Exception/AppCheckApiExceptionConverter.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kreait\Firebase\Exception;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface as StatusCode;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Kreait\Firebase\Exception\AppCheck\ApiConnectionFailed;
|
||||
use Kreait\Firebase\Exception\AppCheck\AppCheckError;
|
||||
use Kreait\Firebase\Exception\AppCheck\PermissionDenied;
|
||||
use Kreait\Firebase\Http\ErrorResponseParser;
|
||||
use Psr\Http\Client\NetworkExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class AppCheckApiExceptionConverter
|
||||
{
|
||||
public function __construct(private readonly ErrorResponseParser $responseParser)
|
||||
{
|
||||
}
|
||||
|
||||
public function convertException(Throwable $exception): AppCheckException
|
||||
{
|
||||
if ($exception instanceof RequestException) {
|
||||
return $this->convertGuzzleRequestException($exception);
|
||||
}
|
||||
|
||||
if ($exception instanceof NetworkExceptionInterface) {
|
||||
return new ApiConnectionFailed('Unable to connect to the API: '.$exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
|
||||
return new AppCheckError($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
|
||||
private function convertGuzzleRequestException(RequestException $e): AppCheckException
|
||||
{
|
||||
$message = $e->getMessage();
|
||||
$code = $e->getCode();
|
||||
$response = $e->getResponse();
|
||||
|
||||
if ($response !== null) {
|
||||
$message = $this->responseParser->getErrorReasonFromResponse($response);
|
||||
$code = $response->getStatusCode();
|
||||
}
|
||||
|
||||
return match ($code) {
|
||||
StatusCode::STATUS_UNAUTHORIZED, StatusCode::STATUS_FORBIDDEN => new PermissionDenied($message, $code, $e),
|
||||
default => new AppCheckError($message, $code, $e),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user