Requests Exception Hierarchy

Exception classes for the Requests library.

Source files:

  • wp-includes/Requests/src/Exception.php
  • wp-includes/Requests/src/Exception/InvalidArgument.php
  • wp-includes/Requests/src/Exception/ArgumentCount.php
  • wp-includes/Requests/src/Exception/Transport.php
  • wp-includes/Requests/src/Exception/Transport/Curl.php

Class Hierarchy

PHPException
├── WpOrgRequestsException
│   ├── WpOrgRequestsExceptionArgumentCount (final)
│   ├── WpOrgRequestsExceptionTransport
│   │   └── WpOrgRequestsExceptionTransportCurl (final)
│   └── WpOrgRequestsExceptionHttp (see class-requests-exception-http.md)
│
PHPInvalidArgumentException
└── WpOrgRequestsExceptionInvalidArgument (final)

WpOrgRequestsException

Base exception for all Requests errors.

Namespace: WpOrgRequests
Package: RequestsExceptions
Extends: Exception

Properties

PropertyTypeVisibilityDescription
$typestringprotectedString error type code
$datamixedprotectedAssociated data

Methods

__construct()

php
public function __construct( string $message, string $type, mixed $data = null, int $code = 0 )
ParameterTypeDescription
$messagestringHuman-readable error message
$typestringString error type identifier
$datamixedAssociated data
$codeintNumerical error code

getType()

php
public function getType(): string

Returns the string type code (similar to getCode() but a string).

getData()

php
public function getData(): mixed

Returns associated data.


WpOrgRequestsExceptionInvalidArgument

Exception for invalid argument types.

Namespace: WpOrgRequestsException
Package: RequestsExceptions
Since: 2.0.0
Modifier: final
Extends: InvalidArgumentException

Methods

create()

Factory method producing a standardized error message.

php
public static function create( int $position, string $name, string $expected, string $received ): InvalidArgument
ParameterTypeDescription
$positionintArgument position (1-based)
$namestringArgument name (e.g., '$host')
$expectedstringExpected type(s) as string
$receivedstringActual type received

Message format: ClassName::methodName(): Argument #1 ($name) must be of type expected, received given

Uses debug_backtrace() to determine the calling class and method.


WpOrgRequestsExceptionArgumentCount

Exception for incorrect number of arguments or array elements.

Namespace: WpOrgRequestsException
Package: RequestsExceptions
Since: 2.0.0
Modifier: final
Extends: WpOrgRequestsException

Methods

create()

Factory method producing a standardized error message.

php
public static function create( string $expected, int $received, string $type ): ArgumentCount
ParameterTypeDescription
$expectedstringExpected count as phrase (e.g., 'an array with exactly two elements')
$receivedintActual count
$typestringException type string for the parent Exception

Message format: ClassName::methodName() expects expected, received given

Uses debug_backtrace() to determine the calling class and method.


WpOrgRequestsExceptionTransport

Base transport exception.

Namespace: WpOrgRequestsException
Package: RequestsExceptions
Extends: WpOrgRequestsException

Empty class — serves as a base type for transport-specific exceptions.


WpOrgRequestsExceptionTransportCurl

cURL-specific transport exception.

Namespace: WpOrgRequestsExceptionTransport
Package: RequestsExceptions
Modifier: final
Extends: WpOrgRequestsExceptionTransport

Constants

ConstantValueDescription
EASY'cURLEasy'cURL easy handle error
MULTI'cURLMulti'cURL multi handle error
SHARE'cURLShare'cURL share handle error

Properties

PropertyTypeDefaultDescription
$codeint-1cURL error code
$typestring'Unknown'Error type: EASY, MULTI, or SHARE
$reasonstring'Unknown'Clear text error message

Methods

__construct()

php
public function __construct( string $message, string $type, mixed $data = null, int $code = 0 )

Sets $type, $code, and $reason from parameters (if non-null). Formats the parent message as "{code} {reason}".

getReason()

php
public function getReason(): string

Returns the clear text error message.