diff --git a/src/Logging/LoggingHelperTrait.php b/src/Logging/LoggingHelperTrait.php index 790ccb37..d6323cb2 100644 --- a/src/Logging/LoggingHelperTrait.php +++ b/src/Logging/LoggingHelperTrait.php @@ -35,7 +35,7 @@ trait LoggingHelperTrait { * @codeCoverageIgnore */ protected function getExceptionResponse(string $method, string $api_call, \Exception $exception): ResponseInterface { - $response = $exception->getResponse(); + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : NULL; if (!$response) { $response = $this->getErrorResponse($exception->getCode(), $exception->getMessage()); } diff --git a/test/ContentHubClientTest.php b/test/ContentHubClientTest.php index 7569a5e6..ce44bbca 100644 --- a/test/ContentHubClientTest.php +++ b/test/ContentHubClientTest.php @@ -350,7 +350,7 @@ public function testExceptionHandling(): void { ]; $log_message = 'Request ID: test-request-uuid, Method: GET, Path: "test-endpoint", Status Code: 202, Reason: some-reason, Error Code: , Error Message: "". Error data: "end-point-not-available"'; $response_code = SymfonyResponse::HTTP_ACCEPTED; - $exception = \Mockery::mock(\Exception::class); + $exception = \Mockery::mock(RequestException::class); $exception->shouldReceive('getResponse') ->andReturn($this->makeMockResponse($response_code, [], json_encode($response_body))); @@ -389,7 +389,7 @@ public function testExceptionHandlingFor404s(): void { ]; $log_message = 'Resource not found in Content Hub: entities/random-uuid.'; $response_code = SymfonyResponse::HTTP_NOT_FOUND; - $exception = \Mockery::mock(\Exception::class); + $exception = \Mockery::mock(RequestException::class); $exception->shouldReceive('getResponse') ->andReturn($this->makeMockResponse($response_code, [], json_encode($response_body)));