Skip to content

Commit 50d1076

Browse files
authored
[DynamoDB] Add waiter for table not exists after delete (#338)
* Add waiter for table delete * WIP rework waiter generator & exception condition * Response::resolve() always throw exceptions, that can be caught * Fix error waiter for sqs * Fallback to full __type error code, like official sdk * Waiter::resolve() ignores http exceptions
1 parent ab9b111 commit 50d1076

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/Exception/Http/HttpExceptionTrait.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public function __construct(ResponseInterface $response)
7070
// The MIME type isn't explicitly checked because some formats inherit from others
7171
// Ex: JSON:API follows RFC 7807 semantics, Hydra can be used in any JSON-LD-compatible format
7272
if ($isJson && $body = json_decode($response->getContent(false), true)) {
73+
if (isset($body['__type'])) {
74+
$parts = explode('#', $body['__type'], 2);
75+
$this->awsCode = $parts[1] ?? $parts[0];
76+
$message .= "\n\n" . $body['__type'] . "\n\n";
77+
}
78+
7379
if (isset($body['hydra:title']) || isset($body['hydra:description'])) {
7480
// see http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors
7581
$separator = isset($body['hydra:title'], $body['hydra:description']) ? "\n\n" : '';

src/Response.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,13 @@ public function __destruct()
5151
* Make sure the actual request is executed.
5252
*
5353
* @param float|null $timeout Duration in seconds before aborting. When null wait until the end of execution.
54-
* @param bool $throw Whether an exception should be thrown on 3/4/5xx status codes
5554
*
5655
* @return bool whether the request is executed or not
5756
*
5857
* @throws NetworkException
5958
* @throws HttpException
6059
*/
61-
final public function resolve(?float $timeout = null, bool $throw = true): bool
60+
final public function resolve(?float $timeout = null): bool
6261
{
6362
if (null !== $this->resolveResult) {
6463
if ($this->resolveResult instanceof \Exception) {
@@ -87,18 +86,16 @@ final public function resolve(?float $timeout = null, bool $throw = true): bool
8786
throw $this->resolveResult = new NetworkException('Could not contact remote server.', 0, $e);
8887
}
8988

90-
if ($throw) {
91-
if (500 <= $statusCode) {
92-
throw $this->resolveResult = new ServerException($this->response);
93-
}
89+
if (500 <= $statusCode) {
90+
throw $this->resolveResult = new ServerException($this->response);
91+
}
9492

95-
if (400 <= $statusCode) {
96-
throw $this->resolveResult = new ClientException($this->response);
97-
}
93+
if (400 <= $statusCode) {
94+
throw $this->resolveResult = new ClientException($this->response);
95+
}
9896

99-
if (300 <= $statusCode) {
100-
throw $this->resolveResult = new RedirectionException($this->response);
101-
}
97+
if (300 <= $statusCode) {
98+
throw $this->resolveResult = new RedirectionException($this->response);
10299
}
103100

104101
return $this->resolveResult = true;

src/Waiter.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function __construct(Response $response, AbstractApi $awsClient, $request
6464

6565
public function __destruct()
6666
{
67-
if (null === $this->resolveResult) {
68-
$this->resolve();
69-
}
67+
$this->resolve();
7068
}
7169

7270
final public function isSuccess(): bool
@@ -94,8 +92,12 @@ final public function getState(): string
9492
$this->stealResponse($this->refreshState());
9593
}
9694

97-
$exception = null;
98-
$this->resolve();
95+
try {
96+
$this->response->resolve();
97+
$exception = null;
98+
} catch (HttpException $exception) {
99+
// use $exception later
100+
}
99101

100102
$state = $this->extractState($this->response, $exception);
101103
$this->needRefresh = true;
@@ -120,13 +122,15 @@ final public function getState(): string
120122
*
121123
* @param float|null $timeout Duration in seconds before aborting. When null wait until the end of execution.
122124
*
123-
* @return bool whether the request is executed or not
124-
*
125125
* @throws NetworkException
126126
*/
127127
final public function resolve(?float $timeout = null): bool
128128
{
129-
return $this->response->resolve($timeout, false);
129+
try {
130+
return $this->response->resolve($timeout);
131+
} catch (HttpException $exception) {
132+
return true;
133+
}
130134
}
131135

132136
/**

0 commit comments

Comments
 (0)