Skip to content

Commit d17465f

Browse files
authored
Update for error generation refactoring (#491)
1 parent 834248c commit d17465f

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected void serializeInputDocument(
8181
TypeScriptWriter writer = context.getWriter();
8282

8383
// Input documents are wrapped in an input shape named wrapper, build that.
84-
writer.openBlock("let wrappedBody: any = {", "};", () -> {
84+
writer.openBlock("const wrappedBody: any = {", "};", () -> {
8585
writer.write("$L: $L,", inputStructure.getId().getName(),
8686
inputStructure.accept(getMemberSerVisitor(context, "input")));
8787
});
@@ -96,7 +96,7 @@ private DocumentMemberSerVisitor getMemberSerVisitor(GenerationContext context,
9696
protected void writeErrorCodeParser(GenerationContext context) {
9797
TypeScriptWriter writer = context.getWriter();
9898

99-
writer.write("let errorTypeParts: String = data[\"__type\"].split('#');");
99+
writer.write("const errorTypeParts: String = data[\"__type\"].split('#');");
100100
writer.write("errorCode = (errorTypeParts[1] === undefined) ? errorTypeParts[0] : errorTypeParts[1];");
101101
}
102102

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import software.amazon.smithy.model.shapes.ShapeIndex;
2626
import software.amazon.smithy.model.shapes.StructureShape;
2727
import software.amazon.smithy.model.shapes.UnionShape;
28-
import software.amazon.smithy.model.traits.ErrorTrait;
2928
import software.amazon.smithy.model.traits.JsonNameTrait;
3029
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
3130
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
@@ -88,16 +87,12 @@ protected void deserializeMap(GenerationContext context, MapShape shape) {
8887
@Override
8988
protected void deserializeStructure(GenerationContext context, StructureShape shape) {
9089
TypeScriptWriter writer = context.getWriter();
91-
boolean isError = shape.hasTrait(ErrorTrait.class);
9290

9391
// Prepare the document contents structure.
9492
// Use a TreeMap to sort the members.
9593
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
9694
writer.openBlock("let contents: any = {", "};", () -> {
9795
writer.write("__type: $S,", shape.getId().getName());
98-
if (isError) {
99-
writer.write("$$fault: $S,", shape.getTrait(ErrorTrait.class).get().getValue());
100-
}
10196
// Set all the members to undefined to meet type constraints.
10297
members.forEach((memberName, memberShape) -> writer.write("$L: undefined,", memberName));
10398
});
@@ -116,11 +111,7 @@ protected void deserializeStructure(GenerationContext context, StructureShape sh
116111
});
117112
});
118113

119-
if (isError) {
120-
writer.write("return Object.assign(new Error($S), contents);", shape.getId().getName());
121-
} else {
122-
writer.write("return contents;");
123-
}
114+
writer.write("return contents;");
124115
}
125116

126117
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void serializeInputDocument(
8787
SymbolProvider symbolProvider = context.getSymbolProvider();
8888
TypeScriptWriter writer = context.getWriter();
8989

90-
writer.write("let bodyParams: any = {};");
90+
writer.write("const bodyParams: any = {};");
9191
for (HttpBinding binding : documentBindings) {
9292
MemberShape member = binding.getMember();
9393
// The name of the member to get from the input shape.
@@ -122,7 +122,7 @@ protected void writeErrorCodeParser(GenerationContext context) {
122122
@Override
123123
public void deserializeOutputDocument(
124124
GenerationContext context,
125-
OperationShape operation,
125+
Shape operationOrError,
126126
List<HttpBinding> documentBindings
127127
) {
128128
TypeScriptWriter writer = context.getWriter();

0 commit comments

Comments
 (0)