error_code = $code; $this->hint = $hint; $this->retryable = $retryable; $this->context = $context; } public function error_code(): string { return $this->error_code; } /** The message as plain text: it's created HTML-escaped (safe if PHP ever prints it) and read back here for JSON and the terminal. */ public function text(): string { return wp_specialchars_decode($this->getMessage(), ENT_QUOTES); } /** The hint as plain text, the same way. */ public function hint(): string { return wp_specialchars_decode($this->hint, ENT_QUOTES); } /** Any exception's message as plain text: a RelayError's read back, any other's as it is. */ public static function text_of(\Throwable $t): string { return $t instanceof self ? $t->text() : $t->getMessage(); } public function retryable(): bool { return $this->retryable; } public function context(): array { return $this->context; } public function to_array(): array { return [ 'code' => $this->error_code, 'message' => $this->text(), 'hint' => $this->hint(), 'retryable' => $this->retryable, 'context' => $this->context, ]; } }