X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2FException%2FRequestException.php;h=06bc96032b5b37b6bb3830fd7847c46bcabe8f6f;hb=HEAD;hp=877664e13ea458f17ed18ed639c2a4360f9d7c5b;hpb=8ef054b51c681e7822133b38f7c5ed9dd2a0f29c;p=m6w6%2Fseekat diff --git a/lib/Exception/RequestException.php b/lib/Exception/RequestException.php index 877664e..06bc960 100644 --- a/lib/Exception/RequestException.php +++ b/lib/Exception/RequestException.php @@ -2,16 +2,28 @@ namespace seekat\Exception; +use http\{Client\Response, Header}; use seekat\Exception; -use http\Header; -use http\Client\Response; - -class RequestException extends \Exception implements Exception -{ +/** + * @code-coverage-ignore + */ +class RequestException extends \Exception implements Exception { + /** + * JSON errors + * @var array + */ private $errors = []; + + /** + * The response of the request which caused the exception + * @var Response + */ private $response; + /** + * @param Response $response + */ function __construct(Response $response) { $this->response = $response; @@ -36,10 +48,26 @@ class RequestException extends \Exception implements Exception parent::__construct($message, $response->getResponseCode(), null); } + /** + * Get JSON errors + * @return array + */ function getErrors() : array { return $this->errors; } + /** + * @return Response + */ + function getResponse() : Response { + return $this->response; + } + + /** + * Combine any errors into a single string + * @staticvar array $reasons + * @return string + */ function getErrorsAsString() { static $reasons = [ "missing" => "The resource %1\$s does not exist\n", @@ -63,6 +91,9 @@ class RequestException extends \Exception implements Exception return $errors; } + /** + * @return string + */ function __toString() : string { return parent::__toString() . "\n". $this->getErrorsAsString(); }