Skip to content

Commit d0f09bb

Browse files
authored
Fix exception not created from HEAD requests (#1724)
1 parent bce2927 commit d0f09bb

File tree

7 files changed

+17
-2
lines changed

7 files changed

+17
-2
lines changed

src/CodeGenerator/src/Generator/OperationGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ private function setMethodBody(Method $method, Operation $operation, ClassName $
198198
$classBuilder->addUse($errorClass->getFqdn());
199199

200200
$mapping[] = sprintf('%s => %s::class,', var_export($error->getCode() ?? $error->getName(), true), $errorClass->getName());
201+
if ('HEAD' === $operation->getHttpMethod() && ($statusCode = $error->getStatusCode()) >= 400) {
202+
$this->requirementsRegistry->addRequirement('async-aws/core', '^1.22');
203+
$mapping[] = sprintf('%s => %s::class,', var_export('http_status_code_' . $statusCode, true), $errorClass->getName());
204+
}
201205
}
202206
if ($mapping) {
203207
$extra .= ", 'exceptionMapping' => [\n" . implode("\n", $mapping) . "\n]";

src/Core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- Added support for exception based on response http status code only.
8+
59
## 1.21.0
610

711
### Added

src/Core/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"extra": {
4040
"branch-alias": {
41-
"dev-master": "1.21-dev"
41+
"dev-master": "1.22-dev"
4242
}
4343
}
4444
}

src/Core/src/Response.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ private function defineResolveStatus(): void
417417

418418
if ((null !== $awsCode = ($awsError ? $awsError->getCode() : null)) && isset($this->exceptionMapping[$awsCode])) {
419419
$exceptionClass = $this->exceptionMapping[$awsCode];
420+
} elseif (isset($this->exceptionMapping['http_status_code_' . $statusCode])) {
421+
$exceptionClass = $this->exceptionMapping['http_status_code_' . $statusCode];
420422
} elseif (500 <= $statusCode) {
421423
$exceptionClass = ServerException::class;
422424
} elseif (400 <= $statusCode) {

src/Service/S3/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Fixed
6+
7+
- Exception NoSuchKeyException not fired for `HeadObject` request.
8+
59
## 2.2.1
610

711
### Changed

src/Service/S3/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ext-dom": "*",
1717
"ext-filter": "*",
1818
"ext-hash": "*",
19-
"async-aws/core": "^1.9"
19+
"async-aws/core": "^1.22"
2020
},
2121
"autoload": {
2222
"psr-4": {

src/Service/S3/src/S3Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@ public function headObject($input): HeadObjectOutput
16301630
$input = HeadObjectRequest::create($input);
16311631
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'HeadObject', 'region' => $input->getRegion(), 'exceptionMapping' => [
16321632
'NoSuchKey' => NoSuchKeyException::class,
1633+
'http_status_code_404' => NoSuchKeyException::class,
16331634
]]));
16341635

16351636
return new HeadObjectOutput($response);

0 commit comments

Comments
 (0)