@wpkernel/core / 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
method
string
path
string
status
number
context?
data?
message?
string
Returns
TransportError
Overrides
Properties
code
readonly code: ErrorCode;Error code - identifies the type of error
Inherited from
method
readonly method: string;HTTP method
path
readonly path: string;Request path
status
readonly status: number;HTTP status code
context?
readonly optional context: ErrorContext;Context in which the error occurred
Inherited from
data?
readonly optional data: ErrorData;Additional data about the error
Inherited from
Methods
fromJSON()
static fromJSON(serialized): WPKernelError;Create WPKernelError from serialized format
Parameters
serialized
Serialized error object
Returns
New WPKernelError instance
Inherited from
isClientError()
isClientError(): boolean;Check if error is a client error (4xx)
Returns
boolean
True if this is a client error
isRetryable()
isRetryable(): boolean;Check if error is retryable
Returns
boolean
True if request should be retried
isServerError()
isServerError(): boolean;Check if error is a server error (5xx)
Returns
boolean
True if this is a server error
isTimeout()
isTimeout(): boolean;Check if error is a network timeout
Returns
boolean
True if this is a timeout error
isWPKernelError()
static isWPKernelError(error): error is WPKernelError;Check if an error is a WPKernelError
Parameters
error
unknown
Error to check
Returns
error is WPKernelError
True if error is a WPKernelError
Inherited from
toJSON()
toJSON(): SerializedError;Serialize error to JSON-safe format
Returns
Serialized error object
Inherited from
wrap()
static wrap(
error,
code,
context?): WPKernelError;Wrap a native Error into a WPKernelError
Parameters
error
Error
Native error to wrap
code
ErrorCode = 'UnknownError'
Error code to assign
context?
Additional context
Returns
New WPKernelError wrapping the original
