| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClient\Providers\Http\Exception; 5 6 use WordPress\AiClientDependencies\Psr\Http\Message\RequestInterface; 7 use WordPress\AiClient\Common\Exception\RuntimeException; 8 use WordPress\AiClient\Providers\Http\DTO\Request; 9 /** 10 * Exception thrown for network-related errors. 11 * 12 * This includes HTTP transport errors, connection failures, 13 * timeouts, and other network-related issues. 14 * 15 * @since 0.2.0 16 */ 17 class NetworkException extends RuntimeException 18 { 19 /** 20 * The request that failed. 21 * 22 * @var Request|null 23 */ 24 protected ?Request $request = null; 25 /** 26 * Returns the request that failed as our Request DTO. 27 * 28 * @since 0.2.0 29 * 30 * @return Request 31 * @throws \RuntimeException If no request is available 32 */ 33 public function getRequest(): Request 34 { 35 if ($this->request === null) { 36 throw new \RuntimeException('Request object not available. This exception was directly instantiated. ' . 'Use a factory method that provides request context.'); 37 } 38 return $this->request; 39 } 40 /** 41 * Creates a NetworkException from a PSR-18 network exception. 42 * 43 * @since 0.2.0 44 * 45 * @param RequestInterface $psrRequest The PSR-7 request that failed. 46 * @param \Throwable $networkException The PSR-18 network exception. 47 * @return self 48 */ 49 public static function fromPsr18NetworkException(RequestInterface $psrRequest, \Throwable $networkException): self 50 { 51 $request = Request::fromPsrRequest($psrRequest); 52 $message = sprintf('Network error occurred while sending request to %s: %s', $request->getUri(), $networkException->getMessage()); 53 $exception = new self($message, 0, $networkException); 54 $exception->request = $request; 55 return $exception; 56 } 57 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |