Skip to content

Commit 3a53cf7

Browse files
authored
Merge pull request #426 from keboola/pepa_PST-1911_dates
PST-1911 Search API fixes
2 parents ba385e2 + 60aa0dc commit 3a53cf7

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/Client.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ private function sendRequest(Request $request): array
572572
} catch (GuzzleClientException $e) {
573573
$body = $this->decodeRequestBody($e->getResponse());
574574
$this->throwExceptionByStringCode($body, $e);
575-
throw new ClientException($e->getMessage(), $e->getCode(), $e);
575+
throw new ClientException($e->getMessage(), $e->getCode(), $e, $body);
576576
} catch (GuzzleException $e) {
577577
throw new ClientException($e->getMessage(), $e->getCode(), $e);
578578
}
@@ -604,24 +604,28 @@ private function throwExceptionByStringCode(array $body, Throwable $previous): v
604604
$previous->getMessage(),
605605
$previous->getCode(),
606606
$previous,
607+
$body,
607608
);
608609
case StateTransitionForbiddenException::STRING_CODE:
609610
throw new StateTransitionForbiddenException(
610611
$previous->getMessage(),
611612
$previous->getCode(),
612613
$previous,
614+
$body,
613615
);
614616
case StateTerminalException::STRING_CODE:
615617
throw new StateTerminalException(
616618
$previous->getMessage(),
617619
$previous->getCode(),
618620
$previous,
621+
$body,
619622
);
620623
case DeduplicationIdConflictException::STRING_CODE:
621624
throw new DeduplicationIdConflictException(
622625
$previous->getMessage(),
623626
$previous->getCode(),
624627
$previous,
628+
$body,
625629
);
626630
}
627631
}

src/Exception/ClientException.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
namespace Keboola\JobQueueInternalClient\Exception;
66

77
use RuntimeException;
8+
use Throwable;
89

910
class ClientException extends RuntimeException
1011
{
12+
public function __construct(
13+
string $message = '',
14+
int $code = 0,
15+
?Throwable $previous = null,
16+
private readonly ?array $responseData = null,
17+
) {
18+
parent::__construct($message, $code, $previous);
19+
}
20+
21+
public function getResponseData(): ?array
22+
{
23+
return $this->responseData;
24+
}
1125
}

tests/ClientFunctionalTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,19 @@ public function testGetJobStartTimeEndTime(): void
393393
public function testGetInvalidJob(): void
394394
{
395395
$client = $this->getClient();
396-
$this->expectException(ClientException::class);
397-
$this->expectExceptionMessage('404 Not Found');
398-
$client->getJob('123456');
396+
397+
try {
398+
$client->getJob('123456');
399+
self::fail('Request should fail');
400+
} catch (ClientException $e) {
401+
self::assertStringContainsString('404 Not Found', $e->getMessage());
402+
self::assertSame(404, $e->getCode());
403+
404+
self::assertIsArray($e->getResponseData());
405+
self::assertSame('error', $e->getResponseData()['status'] ?? null);
406+
self::assertSame('Job "123456" not found', $e->getResponseData()['error'] ?? null);
407+
self::assertSame([], $e->getResponseData()['context'] ?? null);
408+
}
399409
}
400410

401411
public function testGetJobsWithStatuses(): void

0 commit comments

Comments
 (0)