Skip to content

CkPayloadException

What CkPayload throws — only when asked.

Raised by any CkPayload reader called with throwIfInvalid: true when wire text — the raw body of a request or response — could not be turned into a bag. Never thrown otherwise: by default those methods answer an empty array instead, and Explain never throws at all. A final class, derived from CkException.

The message names the method and says why the text could not be read:

CkPayload.FromJson: cannot read the payload — not valid JSON.

Properties

Property Type What it holds
Input mixed From CkException: the value that failed, untouched.
Reason string From CkException: why, in a few words.

Quick look

use SafeCoder\CommonKit\CkPayload;
use SafeCoder\CommonKit\Exceptions\CkPayloadException;

try {
    CkPayload::FromJson(
        json: 'not json',
        throwIfInvalid: true
    );
} catch (CkPayloadException $error) {
    echo $error->Reason;   // -> 'not valid JSON'
    echo $error->Input;    // -> 'not json'
}