Skip to content

Commit c081372

Browse files
committed
chore(codegen): support AwsQueryError trait
1 parent cd6bcf5 commit c081372

File tree

1 file changed

+23
-0
lines changed
  • codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515

1616
package software.amazon.smithy.aws.typescript.codegen;
1717

18+
import java.util.Map;
19+
import java.util.Optional;
1820
import java.util.Set;
21+
import java.util.TreeMap;
22+
import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait;
1923
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
2024
import software.amazon.smithy.codegen.core.SymbolReference;
2125
import software.amazon.smithy.model.shapes.OperationShape;
@@ -171,4 +175,23 @@ protected void deserializeOutputDocument(
171175
public void generateProtocolTests(GenerationContext context) {
172176
AwsProtocolUtils.generateProtocolTests(this, context);
173177
}
178+
179+
@Override
180+
public Map<String, ShapeId> getOperationErrors(GenerationContext context, OperationShape operation) {
181+
Map<String, ShapeId> errors = new TreeMap<>();
182+
183+
operation.getErrors().forEach(shapeId -> {
184+
Shape errorShape = context.getModel().expectShape(shapeId);
185+
String errorName = shapeId.getName(context.getService());
186+
187+
Optional<AwsQueryErrorTrait> errorShapeTrait = errorShape.getTrait(AwsQueryErrorTrait.class);
188+
if (errorShapeTrait.isPresent()) {
189+
errors.put(errorShapeTrait.get().getCode(), shapeId);
190+
} else {
191+
errors.put(errorName, shapeId);
192+
}
193+
});
194+
195+
return errors;
196+
}
174197
}

0 commit comments

Comments
 (0)