update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
76
vendor/google/gax/src/ApiException.php
vendored
76
vendor/google/gax/src/ApiException.php
vendored
@@ -46,6 +46,7 @@ class ApiException extends Exception
|
||||
private $metadata;
|
||||
private $basicMessage;
|
||||
private $decodedMetadataErrorInfo;
|
||||
private array $protobufErrors;
|
||||
|
||||
/**
|
||||
* ApiException constructor.
|
||||
@@ -62,7 +63,8 @@ public function __construct(
|
||||
string $message,
|
||||
int $code,
|
||||
?string $status = null,
|
||||
array $optionalArgs = []
|
||||
array $optionalArgs = [],
|
||||
array $protobufErrors = [],
|
||||
) {
|
||||
$optionalArgs += [
|
||||
'previous' => null,
|
||||
@@ -76,6 +78,7 @@ public function __construct(
|
||||
if ($this->metadata) {
|
||||
$this->decodedMetadataErrorInfo = self::decodeMetadataErrorInfo($this->metadata);
|
||||
}
|
||||
$this->protobufErrors = $protobufErrors;
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
@@ -137,6 +140,15 @@ public function getErrorInfoMetadata()
|
||||
return ($this->decodedMetadataErrorInfo) ? $this->decodedMetadataErrorInfo['errorInfoMetadata'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unserialized errors
|
||||
* @return array
|
||||
*/
|
||||
public function getErrorDetails(): array
|
||||
{
|
||||
return $this->protobufErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $status
|
||||
* @return ApiException
|
||||
@@ -144,11 +156,14 @@ public function getErrorInfoMetadata()
|
||||
public static function createFromStdClass(stdClass $status)
|
||||
{
|
||||
$metadata = property_exists($status, 'metadata') ? $status->metadata : null;
|
||||
$errors = [];
|
||||
|
||||
return self::create(
|
||||
$status->details,
|
||||
$status->code,
|
||||
$metadata,
|
||||
Serializer::decodeMetadata((array) $metadata)
|
||||
Serializer::decodeMetadata((array) $metadata, $errors),
|
||||
$errors,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,11 +180,13 @@ public static function createFromApiResponse(
|
||||
?array $metadata = null,
|
||||
?Exception $previous = null
|
||||
) {
|
||||
$errors = [];
|
||||
return self::create(
|
||||
$basicMessage,
|
||||
$rpcCode,
|
||||
$metadata,
|
||||
Serializer::decodeMetadata((array) $metadata),
|
||||
Serializer::decodeMetadata((array) $metadata, $errors),
|
||||
$errors,
|
||||
$previous
|
||||
);
|
||||
}
|
||||
@@ -194,6 +211,7 @@ public static function createFromRestApiResponse(
|
||||
$rpcCode,
|
||||
$metadata,
|
||||
is_null($metadata) ? [] : $metadata,
|
||||
self::decodeMetadataToProtobufErrors($metadata ?? []),
|
||||
$previous
|
||||
);
|
||||
}
|
||||
@@ -235,6 +253,7 @@ private static function containsErrorInfo(array $decodedMetadata)
|
||||
* @param int $rpcCode
|
||||
* @param iterable|null $metadata
|
||||
* @param array $decodedMetadata
|
||||
* @param array|null $protobufErrors
|
||||
* @param Exception|null $previous
|
||||
* @return ApiException
|
||||
*/
|
||||
@@ -243,6 +262,7 @@ private static function create(
|
||||
int $rpcCode,
|
||||
$metadata,
|
||||
array $decodedMetadata,
|
||||
?array $protobufErrors = null,
|
||||
?Exception $previous = null
|
||||
) {
|
||||
$containsErrorInfo = self::containsErrorInfo($decodedMetadata);
|
||||
@@ -263,11 +283,51 @@ private static function create(
|
||||
$metadata = iterator_to_array($metadata);
|
||||
}
|
||||
|
||||
return new ApiException($message, $rpcCode, $rpcStatus, [
|
||||
'previous' => $previous,
|
||||
'metadata' => $metadata,
|
||||
'basicMessage' => $basicMessage,
|
||||
]);
|
||||
return new ApiException(
|
||||
$message,
|
||||
$rpcCode,
|
||||
$rpcStatus,
|
||||
[
|
||||
'previous' => $previous,
|
||||
'metadata' => $metadata,
|
||||
'basicMessage' => $basicMessage,
|
||||
],
|
||||
$protobufErrors ?? []
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes decoded metadata to the Protobuf error type
|
||||
*
|
||||
* @param array $metadata
|
||||
* @return array
|
||||
*/
|
||||
private static function decodeMetadataToProtobufErrors(array $metadata): array
|
||||
{
|
||||
$result = [];
|
||||
Serializer::loadKnownMetadataTypes();
|
||||
|
||||
foreach ($metadata as $error) {
|
||||
$message = null;
|
||||
|
||||
if (!isset($error['@type'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $error['@type'];
|
||||
|
||||
if (!isset(KnownTypes::TYPE_URLS[$type])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$class = KnownTypes::TYPE_URLS[$type];
|
||||
$message = new $class();
|
||||
$jsonMessage = json_encode(array_diff_key($error, ['@type' => true]));
|
||||
$message->mergeFromJsonString($jsonMessage);
|
||||
$result[] = $message;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user