Skip to content

Commit 3bd2f0e

Browse files
authored
Avoid overriding the exception message with the raw message (#1516)
1 parent 8ce7606 commit 3bd2f0e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Generator/ResponseParser/RestJsonParser.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function generate(StructureShape $shape, bool $throwOnError = true): Pars
6868
return new ParserResult(strtr('$this->PROPERTY_NAME = $response->getContent(THROW);', ['THROW' => $throwOnError ? '' : 'false', 'PROPERTY_NAME' => GeneratorHelper::normalizeName($payloadProperty)]));
6969
}
7070

71+
$forException = !$throwOnError;
72+
7173
$properties = [];
7274
$this->functions = [];
7375
$this->generatedFunctions = [];
@@ -77,6 +79,11 @@ public function generate(StructureShape $shape, bool $throwOnError = true): Pars
7779
continue;
7880
}
7981

82+
// Avoid conflicts with PHP properties. Those AWS members are included in the AWSError anyway.
83+
if ($forException && \in_array(strtolower($member->getName()), ['code', 'message'])) {
84+
continue;
85+
}
86+
8087
if (!$member->isNullable() && !$member->isRequired()) {
8188
$properties[] = strtr('if (null !== $v = (PROPERTY_ACCESSOR)) {
8289
$this->PROPERTY_NAME = $v;

src/Generator/ResponseParser/RestXmlParser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ public function generate(StructureShape $shape, bool $throwOnError = true): Pars
6969
'PROPERTY_ACCESSOR' => $this->parseXmlElement('$data', $member->getShape(), $member->isRequired() || null === $shape->getResultWrapper(), false),
7070
]);
7171
} else {
72+
$forException = !$throwOnError;
7273
foreach ($shape->getMembers() as $member) {
7374
if (\in_array($member->getLocation(), ['header', 'headers'])) {
7475
continue;
7576
}
7677

78+
// Avoid conflicts with PHP properties. Those AWS members are included in the AWSError anyway.
79+
if ($forException && \in_array(strtolower($member->getName()), ['code', 'message'])) {
80+
continue;
81+
}
82+
7783
if (!$member->isNullable() && !$member->isRequired()) {
7884
$properties[] = strtr('if (null !== $v = (PROPERTY_ACCESSOR)) {
7985
$this->PROPERTY_NAME = $v;

0 commit comments

Comments
 (0)