diff --git a/src/Endpoint/Abstracts/AbstractEndpoint.php b/src/Endpoint/Abstracts/AbstractEndpoint.php index f1604c6..9e38e7e 100644 --- a/src/Endpoint/Abstracts/AbstractEndpoint.php +++ b/src/Endpoint/Abstracts/AbstractEndpoint.php @@ -200,9 +200,9 @@ protected function setResponse(Response $_response): static /** * @inheritdoc */ - public function getResponse(): Response + public function getResponse(): Response|null { - return $this->_response; + return $this->_response ?? null; } public function getResponseBody(bool $associative = true): mixed @@ -263,7 +263,10 @@ function (Response $res) use ($options): void { } }, function (RequestException $e) use ($options): void { - $this->setResponse($e->getResponse()); + $response = $e->getResponse(); + if ($response instanceof Response) { + $this->setResponse($response); + } if (isset($options['error']) && is_callable($options['error'])) { $options['error']($e); } diff --git a/src/Endpoint/Interfaces/EndpointInterface.php b/src/Endpoint/Interfaces/EndpointInterface.php index c7d6abd..60a1af1 100644 --- a/src/Endpoint/Interfaces/EndpointInterface.php +++ b/src/Endpoint/Interfaces/EndpointInterface.php @@ -53,7 +53,7 @@ public function execute(): static; /** * Get the Response Object being used by the Endpoint */ - public function getResponse(): Response; + public function getResponse(): Response|null; /** * Check if authentication should be applied