Copied!

Represents an exception thrown during an RPC.

Instantiable
Methods
public __construct(string $message, int $code, ?string $status = NULL, array $optionalArgs = [])
 

ApiException constructor.

  • param string $message
  • param int $code
  • param string|null $status
  • param array $optionalArgs { @type Exception|null $previous @type array|null $metadata @type string|null $basicMessage }
public __toString() : string
 

String representation of ApiException

  • return string
public Exception::__wakeup()
public static createFromApiResponse( $basicMessage, $rpcCode, ?array $metadata = NULL, ?Exception $previous = NULL)
 
  • param string $basicMessage
  • param int $rpcCode
  • param array|null $metadata
  • param \Exception $previous
  • return \ApiException
public static createFromRequestException(GuzzleHttp\Exception\RequestException $ex, bool $isStream = false)
 

Creates an ApiException from a GuzzleHttp RequestException.

  • param \RequestException $ex
  • param bool $isStream
  • return \ApiException
  • throws \ValidationException
public static createFromRestApiResponse( $basicMessage, $rpcCode, ?array $metadata = NULL, ?Exception $previous = NULL)
 

For REST-based responses, the metadata does not need to be decoded.

  • param string $basicMessage
  • param int $rpcCode
  • param array|null $metadata
  • param \Exception $previous
  • return \ApiException
public static createFromRpcStatus(Google\Rpc\Status $status)
 
  • param \Status $status
  • return \ApiException
public static createFromStdClass(stdClass $status)
 
  • param \stdClass $status
  • return \ApiException
public getBasicMessage()
 
  • return null|string
public final Exception::getCode()
public getDomain()
 

Returns the domain in ErrorInfo for an exception, or null if there is no ErrorInfo.

  • return string|null $domain
public getErrorInfoMetadata()
 

Returns the metadata in ErrorInfo for an exception, or null if there is no ErrorInfo.

  • return array|null $errorInfoMetadata
public final Exception::getFile() : string
public final Exception::getLine() : int
public final Exception::getMessage() : string
public getMetadata()
 
  • return array
public final Exception::getPrevious() : ?Throwable
public getReason()
 

Returns the reason in ErrorInfo for an exception, or null if there is no ErrorInfo.

  • return string|null $reason
public getStatus()
public final Exception::getTrace() : array
public final Exception::getTraceAsString() : string
Properties
protected Exception::$code = 0
protected string Exception::$file = ''
protected int Exception::$line = 0
protected Exception::$message = ''
Properties
private $basicMessage = NULL
private $decodedMetadataErrorInfo = NULL
private $metadata = NULL
private $status = NULL
Methods
private static containsErrorInfo(array $decodedMetadata)
 

Checks if decoded metadata includes errorInfo message.

If errorInfo is set, it will always contain reason, domain, and metadata keys.

  • param array $decodedMetadata
  • return array { @type string $reason @type string $domain @type array $errorInfoMetadata }
private static create(string $basicMessage, int $rpcCode, $metadata, array $decodedMetadata, ?Exception $previous = NULL)
 

Construct an ApiException with a useful message, including decoded metadata.

If the decoded metadata includes an errorInfo message, then the domain, reason, and metadata fields from that message are hoisted directly into the error.

  • param string $basicMessage
  • param int $rpcCode
  • param iterable|null $metadata
  • param array $decodedMetadata
  • param \Exception|null $previous
  • return \ApiException
private static decodeMetadataErrorInfo(array $metadata)
 

Returns null if metadata does not contain error info, or returns containsErrorInfo() array if the metadata does contain error info.

  • param array $metadata
  • return array $details { @type string|null $reason @type string|null $domain @type array|null $errorInfoMetadata }
Methods
private static containsErrorInfo(array $decodedMetadata)
 

Checks if decoded metadata includes errorInfo message.

If errorInfo is set, it will always contain reason, domain, and metadata keys.

  • param array $decodedMetadata
  • return array { @type string $reason @type string $domain @type array $errorInfoMetadata }
private static create(string $basicMessage, int $rpcCode, $metadata, array $decodedMetadata, ?Exception $previous = NULL)
 

Construct an ApiException with a useful message, including decoded metadata.

If the decoded metadata includes an errorInfo message, then the domain, reason, and metadata fields from that message are hoisted directly into the error.

  • param string $basicMessage
  • param int $rpcCode
  • param iterable|null $metadata
  • param array $decodedMetadata
  • param \Exception|null $previous
  • return \ApiException
public static createFromApiResponse( $basicMessage, $rpcCode, ?array $metadata = NULL, ?Exception $previous = NULL)
 
  • param string $basicMessage
  • param int $rpcCode
  • param array|null $metadata
  • param \Exception $previous
  • return \ApiException
public static createFromRequestException(GuzzleHttp\Exception\RequestException $ex, bool $isStream = false)
 

Creates an ApiException from a GuzzleHttp RequestException.

  • param \RequestException $ex
  • param bool $isStream
  • return \ApiException
  • throws \ValidationException
public static createFromRestApiResponse( $basicMessage, $rpcCode, ?array $metadata = NULL, ?Exception $previous = NULL)
 

For REST-based responses, the metadata does not need to be decoded.

  • param string $basicMessage
  • param int $rpcCode
  • param array|null $metadata
  • param \Exception $previous
  • return \ApiException
public static createFromRpcStatus(Google\Rpc\Status $status)
 
  • param \Status $status
  • return \ApiException
public static createFromStdClass(stdClass $status)
 
  • param \stdClass $status
  • return \ApiException
private static decodeMetadataErrorInfo(array $metadata)
 

Returns null if metadata does not contain error info, or returns containsErrorInfo() array if the metadata does contain error info.

  • param array $metadata
  • return array $details { @type string|null $reason @type string|null $domain @type array|null $errorInfoMetadata }
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration