Skip to content

Commit 4c93f11

Browse files
Dont generate switch for "never" error serializers
This updates the error handler generation to just throw if there are no modeled errors. This avoids compile time errors when trying to access the `name` attribute.
1 parent 1735105 commit 4c93f11

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerCommandGenerator.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,18 @@ private void writeErrorChecker() {
182182
private void writeErrorHandler() {
183183
writer.addImport("SerdeContext", null, "@aws-sdk/types");
184184
writer.openBlock("serializeError(error: $T, ctx: Omit<SerdeContext, 'endpoint'>): Promise<$T> {", "}",
185-
errorsType, applicationProtocol.getResponseType(), () -> {
186-
writer.openBlock("switch (error.name) {", "}", () -> {
187-
for (ShapeId errorId : operation.getErrors()) {
188-
writeErrorHandlerCase(errorId);
185+
errorsType, applicationProtocol.getResponseType(), () -> {
186+
if (operation.getErrors().isEmpty()) {
187+
writer.write("throw error;");
188+
} else {
189+
writer.openBlock("switch (error.name) {", "}", () -> {
190+
for (ShapeId errorId : operation.getErrors()) {
191+
writeErrorHandlerCase(errorId);
192+
}
193+
writer.openBlock("default: {", "}", () -> writer.write("throw error;"));
194+
});
189195
}
190-
writer.openBlock("default: {", "}", () -> writer.write("throw error;"));
191196
});
192-
});
193197
writer.write("");
194198
}
195199

0 commit comments

Comments
 (0)