Skip to content

Commit

Permalink
Fix exception message when PSR18UnexpectedPushGatewayResponse is thrown
Browse files Browse the repository at this point in the history
The message was incorrect, it contained only some details but the
context was missing.
  • Loading branch information
LeSuisse committed Dec 6, 2023
1 parent bfd750c commit 8357c1e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/PushGateway/PSR18UnexpectedPushGatewayResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ private function __construct(private RequestInterface $request, private Response
{
$exceptionCode = 0;

$message = 'Cannot connect PushGateway server to ' . $request->getUri()->__toString() . ':';
$message = 'Cannot connect PushGateway server to ' . $request->getUri()->__toString();
if ($response !== null) {
$message = ' ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase();
$message .= ': ' . $response->getStatusCode() . ' ' . $response->getReasonPhrase();
}

if ($clientException !== null) {
$message = ' ' . $clientException->getMessage();
$message .= ': ' . $clientException->getMessage();
$exceptionCode = $clientException->getCode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testInvalidResponse(): void

$exception = PSR18UnexpectedPushGatewayResponse::invalidResponse($request, $response);

self::assertStringContainsString('Cannot connect PushGateway server to /: 500 Internal', $exception->getMessage());
self::assertSame($request, $exception->getRequest());
self::assertSame($response, $exception->getResponse());
self::assertNull($exception->getPrevious());
Expand All @@ -29,11 +30,12 @@ public function testInvalidResponse(): void
public function testRequestFailure(): void
{
$request = Psr17FactoryDiscovery::findRequestFactory()->createRequest('PUT', '/');
$clientException = new class extends Exception implements ClientExceptionInterface {
$clientException = new class ('some reason') extends Exception implements ClientExceptionInterface {
};

$exception = PSR18UnexpectedPushGatewayResponse::requestFailure($request, $clientException);

self::assertStringContainsString('Cannot connect PushGateway server to /: some reason', $exception->getMessage());
self::assertSame($request, $exception->getRequest());
self::assertNull($exception->getResponse());
self::assertSame($clientException, $exception->getPrevious());
Expand Down

0 comments on commit 8357c1e

Please sign in to comment.