Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849<?php
declare(strict_types=1);
namespace Wotnak\Atproto\Exception;
/** * XRPC response with a non-2xx HTTP status. * * @api */final class XrpcHttpException extends XrpcException {
private const MAX_MESSAGE_VALUE_BYTES = 512;
/** * @param array<string, mixed>|null $decodedBody * @param array<string, list<string>> $headers */ public function __construct( string $method, string $serviceUrl, public readonly int $statusCode, public readonly string $responseBody, public readonly ?array $decodedBody = NULL, public readonly ?string $xrpcError = NULL, public readonly ?string $xrpcMessage = NULL, public readonly array $headers = [], ) { $message = \sprintf('XRPC request %s failed with HTTP %d.', $method, $statusCode); if ($xrpcError !== NULL) { $message .= ' ' . self::summarize($xrpcError); if ($xrpcMessage !== NULL && $xrpcMessage !== '') { $message .= ': ' . self::summarize($xrpcMessage); } }
parent::__construct($message, $method, $serviceUrl); }
private static function summarize(string $value): string { if (\strlen($value) <= self::MAX_MESSAGE_VALUE_BYTES) { return $value; } return \substr($value, 0, self::MAX_MESSAGE_VALUE_BYTES) . '...'; }
}