Skip to content

Commit

Permalink
LCH-6798: Handle exceptions which do not have response objects. (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
narendradesai authored Dec 6, 2023
1 parent 6bf0bd3 commit cb71e21
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Logging/LoggingHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions test/ContentHubClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down Expand Up @@ -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)));

Expand Down

0 comments on commit cb71e21

Please sign in to comment.