Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ public void generateResponseDeserializers(GenerationContext context) {
this::writeErrorCodeParser,
isErrorCodeInBody,
this::getErrorBodyLocation,
this::getOperationErrors
this::getOperationErrors,
getErrorAliases(context, containedOperations)
);
deserializingErrorShapes.addAll(errorShapes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
Expand Down Expand Up @@ -318,7 +319,8 @@ public static Set<StructureShape> generateUnifiedErrorDispatcher(
Consumer<GenerationContext> errorCodeGenerator,
boolean shouldParseErrorBody,
BiFunction<GenerationContext, String, String> bodyErrorLocationModifier,
BiFunction<GenerationContext, List<OperationShape>, Map<String, ShapeId>> operationErrorsToShapes
BiFunction<GenerationContext, List<OperationShape>, Map<String, ShapeId>> operationErrorsToShapes,
Map<String, TreeSet<String>> errorAliases
) {
TypeScriptWriter writer = context.getWriter();
SymbolProvider symbolProvider = context.getSymbolProvider();
Expand Down Expand Up @@ -385,6 +387,11 @@ public static Set<StructureShape> generateUnifiedErrorDispatcher(
String outputParam = shouldParseErrorBody ? "parsedOutput" : "output";
writer.write("case $S:", name);
writer.write("case $S:", errorId.toString());
for (String alias : errorAliases.getOrDefault(errorId.toString(), new TreeSet<>())) {
if (!Objects.equals(name, alias) && !Objects.equals(errorId.toString(), alias)) {
writer.write("case $S:", alias);
}
}
writer.indent()
.write("throw await $L($L, context);", errorDeserMethodName, outputParam)
.dedent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public void generateResponseDeserializers(GenerationContext context) {
this::writeErrorCodeParser,
isErrorCodeInBody,
this::getErrorBodyLocation,
this::getOperationErrors
this::getOperationErrors,
getErrorAliases(context, containedOperations)
);
deserializingErrorShapes.addAll(errorShapes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
package software.amazon.smithy.typescript.codegen.integration;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.codegen.core.Symbol;
Expand Down Expand Up @@ -321,6 +323,15 @@ default Map<String, ShapeId> getOperationErrors(GenerationContext context, Colle
return errors;
}

/**
* @return map of fully qualified shape id to aliases and/or short names that should map to the same error.
*/
default Map<String, TreeSet<String>> getErrorAliases(
GenerationContext context, Collection<OperationShape> operations
) {
return Collections.emptyMap();
}

/**
* Context object used for service serialization and deserialization.
*/
Expand Down