4
4
import static software .amazon .smithy .aws .go .codegen .AwsProtocolUtils .handleDecodeError ;
5
5
import static software .amazon .smithy .aws .go .codegen .XmlProtocolUtils .initializeXmlDecoder ;
6
6
7
+ import java .util .Map ;
8
+ import java .util .Optional ;
7
9
import java .util .Set ;
10
+ import java .util .TreeMap ;
11
+ import software .amazon .smithy .aws .traits .protocols .AwsQueryErrorTrait ;
8
12
import software .amazon .smithy .aws .traits .protocols .AwsQueryTrait ;
9
13
import software .amazon .smithy .codegen .core .Symbol ;
10
14
import software .amazon .smithy .go .codegen .GoWriter ;
25
29
* Handles generating the aws query protocol for services.
26
30
*
27
31
* @inheritDoc
28
- *
29
32
* @see HttpRpcProtocolGenerator
30
33
*/
31
34
class AwsQuery extends HttpRpcProtocolGenerator {
@@ -81,8 +84,8 @@ protected void serializeInputDocument(GenerationContext context, OperationShape
81
84
82
85
writer .openBlock ("if request, err = request.SetStream(bytes.NewReader(bodyWriter.Bytes())); err != nil {" ,
83
86
"}" , () -> {
84
- writer .write ("return out, metadata, &smithy.SerializationError{Err: err}" );
85
- });
87
+ writer .write ("return out, metadata, &smithy.SerializationError{Err: err}" );
88
+ });
86
89
}
87
90
88
91
@ Override
@@ -97,7 +100,7 @@ protected void deserializeOutputDocument(GenerationContext context, OperationSha
97
100
StructureShape output = ProtocolUtils .expectOutput (context .getModel (), operation );
98
101
String functionName = ProtocolGenerator .getDocumentDeserializerFunctionName (
99
102
output , context .getService (), getProtocolName ());
100
- initializeXmlDecoder (writer , "response.Body" , "out, metadata, " ,"nil" );
103
+ initializeXmlDecoder (writer , "response.Body" , "out, metadata, " , "nil" );
101
104
unwrapOutputDocument (context , operation );
102
105
writer .write ("err = $L(&output, decoder)" , functionName );
103
106
handleDecodeError (writer , "out, metadata, " );
@@ -152,4 +155,21 @@ protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
152
155
public void generateProtocolTests (GenerationContext context ) {
153
156
AwsProtocolUtils .generateHttpProtocolTests (context );
154
157
}
158
+
159
+ @ Override
160
+ public Map <String , ShapeId > getOperationErrors (GenerationContext context , OperationShape operation ) {
161
+ Map <String , ShapeId > errors = new TreeMap <>();
162
+
163
+ operation .getErrors ().forEach (shapeId -> {
164
+ Shape errorShape = context .getModel ().expectShape (shapeId );
165
+ String errorName = shapeId .getName (context .getService ());
166
+
167
+ errors .put (errorName , shapeId );
168
+
169
+ errorShape .getTrait (AwsQueryErrorTrait .class ).ifPresent (awsQueryErrorTrait ->
170
+ errors .put (awsQueryErrorTrait .getCode (), shapeId ));
171
+ });
172
+
173
+ return errors ;
174
+ }
155
175
}
0 commit comments