friendship ended with social-app. php is my new best friend
at main 1.2 kB view raw
1<?php 2 3namespace React\Http\Message; 4 5use RuntimeException; 6use Psr\Http\Message\ResponseInterface; 7 8/** 9 * The `React\Http\Message\ResponseException` is an `Exception` sub-class that will be used to reject 10 * a request promise if the remote server returns a non-success status code 11 * (anything but 2xx or 3xx). 12 * You can control this behavior via the [`withRejectErrorResponse()` method](#withrejecterrorresponse). 13 * 14 * The `getCode(): int` method can be used to 15 * return the HTTP response status code. 16 */ 17final class ResponseException extends RuntimeException 18{ 19 private $response; 20 21 public function __construct(ResponseInterface $response, $message = null, $code = null, $previous = null) 22 { 23 if ($message === null) { 24 $message = 'HTTP status code ' . $response->getStatusCode() . ' (' . $response->getReasonPhrase() . ')'; 25 } 26 if ($code === null) { 27 $code = $response->getStatusCode(); 28 } 29 parent::__construct($message, $code, $previous); 30 31 $this->response = $response; 32 } 33 34 /** 35 * Access its underlying response object. 36 * 37 * @return ResponseInterface 38 */ 39 public function getResponse() 40 { 41 return $this->response; 42 } 43}