WP Kernel API / core/src / TransportError
Class: TransportError
Error thrown when a network/HTTP request fails
Example
throw new TransportError({
status: 404,
path: '/my-plugin/v1/things/123',
method: 'GET',
message: 'Resource not found'
});
Extends
Constructors
Constructor
new TransportError(options): TransportError;
Create a new TransportError
Parameters
options
Transport error options
status
number
path
string
method
string
message?
string
data?
context?
Returns
TransportError
Overrides
Properties
code
readonly code: ErrorCode;
Error code - identifies the type of error
Inherited from
data?
readonly optional data: ErrorData;
Additional data about the error
Inherited from
context?
readonly optional context: ErrorContext;
Context in which the error occurred
Inherited from
status
readonly status: number;
HTTP status code
path
readonly path: string;
Request path
method
readonly method: string;
HTTP method
Methods
toJSON()
toJSON(): SerializedError;
Serialize error to JSON-safe format
Returns
Serialized error object
Inherited from
fromJSON()
static fromJSON(serialized): KernelError;
Create KernelError from serialized format
Parameters
serialized
Serialized error object
Returns
New KernelError instance
Inherited from
isKernelError()
static isKernelError(error): error is KernelError;
Check if an error is a KernelError
Parameters
error
unknown
Error to check
Returns
error is KernelError
True if error is a KernelError
Inherited from
wrap()
static wrap(
error,
code,
context?): KernelError;
Wrap a native Error into a KernelError
Parameters
error
Error
Native error to wrap
code
ErrorCode
= 'UnknownError'
Error code to assign
context?
Additional context
Returns
New KernelError wrapping the original
Inherited from
isTimeout()
isTimeout(): boolean;
Check if error is a network timeout
Returns
boolean
True if this is a timeout error
isRetryable()
isRetryable(): boolean;
Check if error is retryable
Returns
boolean
True if request should be retried
isClientError()
isClientError(): boolean;
Check if error is a client error (4xx)
Returns
boolean
True if this is a client error
isServerError()
isServerError(): boolean;
Check if error is a server error (5xx)
Returns
boolean
True if this is a server error