WP Kernel API / core/src / error / PolicyDeniedError
Class: PolicyDeniedError
Error thrown when a policy assertion fails
Example
throw new PolicyDeniedError({
namespace: 'my-plugin',
policyKey: 'posts.edit',
params: { postId: 123 },
message: 'You do not have permission to edit this post'
});
Extends
Constructors
Constructor
new PolicyDeniedError(options): PolicyDeniedError;
Create a new PolicyDeniedError
Parameters
options
Policy denied error options
namespace
string
Plugin namespace
policyKey
string
Policy key that was denied
params?
unknown
Parameters passed to policy check
message?
string
Optional custom error message
data?
Additional error data
context?
Additional error context
Returns
PolicyDeniedError
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
messageKey
readonly messageKey: string;
I18n message key for user-facing error messages Format: policy.denied.{namespace}.{policyKey}
policyKey
readonly policyKey: string;
Policy key that was denied
namespace
readonly namespace: string;
Plugin namespace
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