*/ public array $body; /** * Seconds from a Retry-After header, or 0. * * @var int */ public int $retryAfter; /** * Transport error message, when there was no answer. * * @var string */ public string $transportError; /** * Build. * * @param int $status HTTP status. * @param array $body Decoded body. * @param int $retryAfter Retry-After seconds. * @param string $transportError Transport error. */ public function __construct( int $status, array $body, int $retryAfter = 0, string $transportError = '' ) { $this->status = $status; $this->body = $body; $this->retryAfter = $retryAfter; $this->transportError = $transportError; } /** * The request did not get an answer. * * @param string $message Why. */ public static function transportError( string $message ): self { return new self( 0, [], 0, $message ); } /** * The contract's error code, e.g. `clock_skew`. */ public function code(): string { return is_string( $this->body['code'] ?? null ) ? $this->body['code'] : ''; } /** * A human-readable reason, for logs and the settings screen. */ public function message(): string { if ( 0 === $this->status ) { return $this->transportError; } $message = is_string( $this->body['message'] ?? null ) ? $this->body['message'] : ''; return trim( 'HTTP ' . $this->status . ' ' . $this->code() . ' ' . $message ); } /** * The hub's clock as a Unix time, or null. */ public function hubTime(): ?int { $time = is_string( $this->body['hub_time'] ?? null ) ? strtotime( $this->body['hub_time'] ) : false; return false === $time ? null : $time; } }