YouTubePHP Documentation

HttpException extends RuntimeException
in package

A request YouTube refused, or one that never got an answer.

Google's errors carry a reason beside the status (quotaExceeded, liveChatEnded, forbidden), and the reason is usually what a caller needs: a quota running out and a chat that ended are both 403s. fromResponse() picks the exception class by reason first and by status after, so each can be caught on its own.

The status is the exception code, and 0 for a failure that never reached YouTube.

Tags
link
https://developers.google.com/youtube/v3/docs/errors
since
1.0.0
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Constants

REASONS  : array<string, HttpException>> = ['quotaExceeded' => \YouTube\Http\Exceptions\Qu...
STATUSES  : array<int, HttpException>> = [400 => \YouTube\Http\Exceptions\BadRequestExce...

Properties

$domain  : ?string
$endpoint  : string
$errors  : array<string|int, mixed>
$reason  : ?string
$response  : ?ResponseInterface

Methods

__construct()  : mixed
fromError()  : self
The exception an error body stands for, with or without the response it came in. A streamed call reports an error that arrives after its headers as one element of the stream, which has no status line of its own.
fromResponse()  : self
The exception an error response stands for.
getDomain()  : ?string
Google's error domain, e.g. `youtube.quota`, when it gave one.
getEndpoint()  : string
The API method called, e.g. `liveChatMessages.list`.
getErrors()  : array<int, array<string, mixed>>
getReason()  : ?string
Google's reason code, e.g. `quotaExceeded`, when it gave one.
getResponse()  : ?ResponseInterface
getRetryAfter()  : ?float
Seconds to wait before trying again, when the response said.
getStatus()  : int
The HTTP status, or 0 when there was no response.
reasonOf()  : ?string
The reason code: the classic `errors[0].reason`, or the `ErrorInfo` detail the newer format uses for scope and rate-limit failures.

Constants

REASONS

private array<string, HttpException>> REASONS = ['quotaExceeded' => \YouTube\Http\Exceptions\QuotaExceededException::class, 'dailyLimitExceeded' => \YouTube\Http\Exceptions\QuotaExceededException::class, 'dailyLimitExceededUnreg' => \YouTube\Http\Exceptions\QuotaExceededException::class, 'rateLimitExceeded' => \YouTube\Http\Exceptions\RateLimitedException::class, 'userRateLimitExceeded' => \YouTube\Http\Exceptions\RateLimitedException::class, 'RATE_LIMIT_EXCEEDED' => \YouTube\Http\Exceptions\RateLimitedException::class, 'liveChatEnded' => \YouTube\Http\Exceptions\LiveChatEndedException::class, 'liveChatDisabled' => \YouTube\Http\Exceptions\LiveChatDisabledException::class, 'liveChatNotFound' => \YouTube\Http\Exceptions\LiveChatNotFoundException::class, 'insufficientPermissions' => \YouTube\Http\Exceptions\MissingScopeException::class, 'ACCESS_TOKEN_SCOPE_INSUFFICIENT' => \YouTube\Http\Exceptions\MissingScopeException::class]

Google's reason => the exception that means it.

STATUSES

private array<int, HttpException>> STATUSES = [400 => \YouTube\Http\Exceptions\BadRequestException::class, 401 => \YouTube\Http\Exceptions\UnauthorizedException::class, 403 => \YouTube\Http\Exceptions\ForbiddenException::class, 404 => \YouTube\Http\Exceptions\NotFoundException::class, 409 => \YouTube\Http\Exceptions\ConflictException::class, 429 => \YouTube\Http\Exceptions\RateLimitedException::class]

Properties

$errors read-only

private array<string|int, mixed> $errors = []

$response read-only

private ?ResponseInterface $response = null

Methods

__construct()

public __construct(string $message[, int $code = 0 ][, string|null $reason = null ][, string|null $domain = null ][, array<int, array<string, mixed>> $errors = [] ][, ?ResponseInterface $response = null ][, string $endpoint = '' ][, ?Throwable $previous = null ]) : mixed
Parameters
$message : string
$code : int = 0

The HTTP status, or 0 when there was no response.

$reason : string|null = null

Google's reason code, e.g. quotaExceeded.

$domain : string|null = null

Google's error domain, e.g. youtube.quota.

$errors : array<int, array<string, mixed>> = []

Every entry of the error's errors list.

$response : ?ResponseInterface = null
$endpoint : string = ''

The API method called, e.g. liveChatMessages.list.

$previous : ?Throwable = null

fromError()

The exception an error body stands for, with or without the response it came in. A streamed call reports an error that arrives after its headers as one element of the stream, which has no status line of its own.

public static fromError(array<string, mixed> $decoded, int $status, string $endpoint[, ?ResponseInterface $response = null ]) : self
Parameters
$decoded : array<string, mixed>

The decoded body: {"error": {...}}.

$status : int

The HTTP status; the error's own code is used when it has one.

$endpoint : string
$response : ?ResponseInterface = null
Return values
self

fromResponse()

The exception an error response stands for.

public static fromResponse(ResponseInterface $response, array<string, mixed>|null $decoded, string $endpoint) : self
Parameters
$response : ResponseInterface
$decoded : array<string, mixed>|null

The decoded body, if it was JSON.

$endpoint : string
Return values
self

getDomain()

Google's error domain, e.g. `youtube.quota`, when it gave one.

public getDomain() : ?string
Return values
?string

getEndpoint()

The API method called, e.g. `liveChatMessages.list`.

public getEndpoint() : string
Return values
string

getErrors()

public getErrors() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>> —

Every entry of the error's errors list.

getReason()

Google's reason code, e.g. `quotaExceeded`, when it gave one.

public getReason() : ?string
Return values
?string

getResponse()

public getResponse() : ?ResponseInterface
Return values
?ResponseInterface

getRetryAfter()

Seconds to wait before trying again, when the response said.

public getRetryAfter() : ?float
Return values
?float

getStatus()

The HTTP status, or 0 when there was no response.

public getStatus() : int
Return values
int

reasonOf()

The reason code: the classic `errors[0].reason`, or the `ErrorInfo` detail the newer format uses for scope and rate-limit failures.

private static reasonOf(array<string, mixed> $error, array<string, mixed> $first) : ?string
Parameters
$error : array<string, mixed>
$first : array<string, mixed>
Return values
?string
On this page

Search results