From 2d8bc836658e09fadfe93f24aa122ca2f002d847 Mon Sep 17 00:00:00 2001 From: fossand Date: Fri, 18 Aug 2023 15:25:49 -0700 Subject: [PATCH] Add protocol test for handling two X-Amzn-Errortype header values --- .../model/awsJson1_0/errors.smithy | 19 ++++++++++++++++++- .../model/awsJson1_1/errors.smithy | 19 ++++++++++++++++++- .../model/restJson1/errors.smithy | 18 +++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/smithy-aws-protocol-tests/model/awsJson1_0/errors.smithy b/smithy-aws-protocol-tests/model/awsJson1_0/errors.smithy index 7da6a4b55a2..2f90361572e 100644 --- a/smithy-aws-protocol-tests/model/awsJson1_0/errors.smithy +++ b/smithy-aws-protocol-tests/model/awsJson1_0/errors.smithy @@ -261,5 +261,22 @@ apply FooError @httpResponseTests([ }""", bodyMediaType: "application/json", appliesTo: "client", - } + }, + { + id: "AwsJson10FooErrorWithMultipleAmznErrorTypes", + documentation: """ + API Gateway always adds its own x-amzn-errortype header on gateway responses. + However, this header does not match the error configured in customers model and \ + results in two X-Amzn-Errortype header values. \ + The first value is provided by the customer and the second value is from API Gateway \ + + Clients need to split the header value on ',' and take only the first element. \ + For example, 'FooError,InvalidParameterException' is to be interpreted as 'FooError'.""", + protocol: awsJson1_0, + code: 400, + headers: { + "X-Amzn-Errortype": "FooError,InvalidParameterException", + }, + appliesTo: "client", + }, ]) diff --git a/smithy-aws-protocol-tests/model/awsJson1_1/errors.smithy b/smithy-aws-protocol-tests/model/awsJson1_1/errors.smithy index c57b6fed010..500996ac39e 100644 --- a/smithy-aws-protocol-tests/model/awsJson1_1/errors.smithy +++ b/smithy-aws-protocol-tests/model/awsJson1_1/errors.smithy @@ -253,5 +253,22 @@ apply FooError @httpResponseTests([ }""", bodyMediaType: "application/json", appliesTo: "client", - } + }, + { + id: "AwsJson11FooErrorWithMultipleAmznErrorTypes", + documentation: """ + API-Gateway always adds its own x-amzn-errortype header on gateway responses. + However, this header does not match the error configured in customers model and \ + results in two X-Amzn-Errortype header values. \ + The first value is provided by the customer and the second value is from API Gateway \ + + Clients need to split the header value on ',' and take only the first element. \ + For example, 'FooError,InvalidParameterException' is to be interpreted as 'FooError'.""", + protocol: awsJson1_1, + code: 400, + headers: { + "X-Amzn-Errortype": "FooError,InvalidParameterException", + }, + appliesTo: "client", + }, ]) diff --git a/smithy-aws-protocol-tests/model/restJson1/errors.smithy b/smithy-aws-protocol-tests/model/restJson1/errors.smithy index 7e387fe0363..a553e2dc5d2 100644 --- a/smithy-aws-protocol-tests/model/restJson1/errors.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/errors.smithy @@ -95,7 +95,6 @@ apply InvalidGreeting @httpResponseTests([ }""", bodyMediaType: "application/json", }, - ]) /// This error is thrown when a request is invalid. @@ -306,5 +305,22 @@ apply FooError @httpResponseTests([ }""", bodyMediaType: "application/json", appliesTo: "client", + }, + { + id: "RestJsonWithMultipleAmznErrorTypes", + documentation: """ + API-Gateway always adds its own x-amzn-errortype header on gateway responses. + However, this header does not match the error configured in customers model and \ + results in two X-Amzn-Errortype header values. \ + The first value is provided by the customer and the second value is from API Gateway \ + + Clients need to split the header value on ',' and take only the first element. \ + For example, 'FooError,InvalidParameterException' is to be interpreted as 'FooError'.""", + protocol: restJson1, + code: 400, + headers: { + "X-Amzn-Errortype": "FooError,InvalidParameterException", + }, + appliesTo: "client", } ])