Skip to content

Commit 5b55db0

Browse files
author
Brian Crowell
committed
Fix #2861: Check error body before dereference
Not a perfect solution, and I certainly have no business editing this code. But I do want to get AWS's attention to get this fixed.
1 parent b0e1422 commit 5b55db0

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsEc2.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ public void generateSharedComponents(GenerationContext context) {
9797
+ " output: $T,\n"
9898
+ " data: any\n"
9999
+ "): string => {", "};", responseType, () -> {
100+
// Default a 503 status code to the Unavailable code.
101+
writer.openBlock("if (output.statusCode == 503) {", "}", () -> writer.write("return 'Unavailable';"));
102+
100103
// Attempt to fetch the error code from the specific location.
101-
String errorCodeLocation = getErrorBodyLocation(context, "data") + ".Code";
102-
writer.openBlock("if ($L !== undefined) {", "}", errorCodeLocation, () -> {
104+
String errorBodyLocation = getErrorBodyLocation(context, "data");
105+
String errorCodeLocation = errorBodyLocation + ".Code";
106+
writer.openBlock("if ($L !== undefined && $L !== undefined) {", "}", errorBodyLocation, errorCodeLocation, () -> {
103107
writer.write("return $L;", errorCodeLocation);
104108
});
105109

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsQuery.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ public void generateSharedComponents(GenerationContext context) {
9797
+ " output: $T,\n"
9898
+ " data: any\n"
9999
+ "): string => {", "};", responseType, () -> {
100+
// Default a 503 status code to the Unavailable code.
101+
writer.openBlock("if (output.statusCode == 503) {", "}", () -> writer.write("return 'Unavailable';"));
102+
100103
// Attempt to fetch the error code from the specific location.
101-
String errorCodeLocation = getErrorBodyLocation(context, "data") + ".Code";
102-
writer.openBlock("if ($L !== undefined) {", "}", errorCodeLocation, () -> {
104+
String errorBodyLocation = getErrorBodyLocation(context, "data");
105+
String errorCodeLocation = errorBodyLocation + ".Code";
106+
writer.openBlock("if ($L !== undefined && $L !== undefined) {", "}", errorBodyLocation, errorCodeLocation, () -> {
103107
writer.write("return $L;", errorCodeLocation);
104108
});
105109

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsRestXml.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,13 @@ public void generateSharedComponents(GenerationContext context) {
110110
+ " output: $T,\n"
111111
+ " data: any\n"
112112
+ "): string => {", "};", responseType, () -> {
113+
// Default a 503 status code to the Unavailable code.
114+
writer.openBlock("if (output.statusCode == 503) {", "}", () -> writer.write("return 'Unavailable';"));
115+
113116
// Attempt to fetch the error code from the specific location.
114-
String errorCodeLocation = getErrorBodyLocation(context, "data") + ".Code";
115-
writer.openBlock("if ($L !== undefined) {", "}", errorCodeLocation, () -> {
117+
String errorBodyLocation = getErrorBodyLocation(context, "data");
118+
String errorCodeLocation = errorBodyLocation + ".Code";
119+
writer.openBlock("if ($L !== undefined && $L !== undefined) {", "}", errorBodyLocation, errorCodeLocation, () -> {
116120
writer.write("return $L;", errorCodeLocation);
117121
});
118122

0 commit comments

Comments
 (0)