Skip to content

Commit

Permalink
fix RPC protocol error deser
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Jan 9, 2020
1 parent 6e477a1 commit 3bb25b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ private List<HttpBinding> readErrorResponseBody(
if (isErrorCodeInBody) {
// Body is already parsed in error dispatcher, simply assign body to data.
writer.write("const data: any = output.body;");
List<HttpBinding> responseBindings = bindingIndex.getResponseBindings(error).values()
.stream().collect(Collectors.toList());
List<HttpBinding> responseBindings = bindingIndex.getResponseBindings(error, Location.DOCUMENT);
responseBindings.sort(Comparator.comparing(HttpBinding::getMemberName));
return responseBindings;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public void generateSharedComponents(GenerationContext context) {
generateDocumentBodyShapeSerializers(context, serializingDocumentShapes);
generateDocumentBodyShapeDeserializers(context, deserializingDocumentShapes);
HttpProtocolGeneratorUtils.generateMetadataDeserializer(context, getApplicationProtocol().getResponseType());
HttpProtocolGeneratorUtils.generateCollectBody(context);
HttpProtocolGeneratorUtils.generateCollectBodyString(context);
}

@Override
Expand Down Expand Up @@ -285,14 +287,20 @@ private void generateErrorDeserializer(GenerationContext context, StructureShape
+ " context: __SerdeContext\n"
+ "): Promise<$T> => {", "};", errorDeserMethodName, outputReference, errorSymbol, () -> {
// First deserialize the body properly.
writer.write("const deserialized: any = $L($L.body, context);",
ProtocolGenerator.getDeserFunctionName(errorSymbol, context.getProtocolName()), outputReference);
if (isErrorCodeInBody) {
writer.write("const body = $L.body", outputReference);
} else {
// If error node not in body, error body is not parsed in dispatcher.
writer.write("const body = parsedBody($L.body, context);", outputReference);
}
writer.write("const deserialized: any = $L(body, context);",
ProtocolGenerator.getDeserFunctionName(errorSymbol, context.getProtocolName()));

// Then load it into the object with additional error and response properties.
writer.openBlock("const contents: $T = {", "};", errorSymbol, () -> {
writer.write("__type: $S,", error.getId().getName());
writer.write("$$fault: $S,", error.getTrait(ErrorTrait.class).get().getValue());
writer.write("$$metadata: deserializeMetadata(output),");
writer.write("$$metadata: deserializeMetadata($L),", outputReference);
writer.write("...deserialized,");
});

Expand Down

0 comments on commit 3bb25b2

Please sign in to comment.