Skip to content

Commit 432ecf3

Browse files
committed
Fix query compatible for JSON services
1 parent 1361161 commit 432ecf3

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

src/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ AWSError<CoreErrors> JsonErrorMarshaller::Marshall(const Aws::Http::HttpResponse
6262

6363
if (httpResponse.HasHeader(ERROR_TYPE_HEADER)) {
6464
error = Marshall(httpResponse.GetHeader(ERROR_TYPE_HEADER), message);
65+
} else if (httpResponse.HasHeader(QUERY_ERROR_HEADER)) {
66+
auto errorCodeString = httpResponse.GetHeader(QUERY_ERROR_HEADER);
67+
auto locationOfSemicolon = errorCodeString.find_first_of(';');
68+
Aws::String errorCode;
69+
70+
if (locationOfSemicolon != Aws::String::npos) {
71+
errorCode = errorCodeString.substr(0, locationOfSemicolon);
72+
} else {
73+
errorCode = errorCodeString;
74+
}
75+
error = Marshall(errorCode, message);
6576
} else if (payloadView.ValueExists(TYPE)) {
6677
error = Marshall(payloadView.GetString(TYPE), message);
6778
} else {
@@ -256,45 +267,6 @@ AWSError<CoreErrors> AWSErrorMarshaller::FindErrorByHttpResponseCode(Aws::Http::
256267
}
257268

258269
void JsonErrorMarshallerQueryCompatible::MarshallError(AWSError<CoreErrors>& error, const Http::HttpResponse& httpResponse) const {
259-
if (!error.GetExceptionName().empty()) {
260-
auto exceptionPayload = GetJsonPayloadHttpResponse(httpResponse);
261-
auto payloadView = JsonView(exceptionPayload);
262-
/*
263-
AWS Query-Compatible mode: This is a special setting that allows
264-
certain AWS services to communicate using a specific "query"
265-
format, which can send customized error codes. Users are divided
266-
into different groups based on how they communicate with the
267-
service: Group #1: Users using the AWS Query format, receiving
268-
custom error codes. Group #2: Users using the regular AWS JSON
269-
format without the trait, receiving standard error codes. Group #3:
270-
Users using the AWS JSON format with the trait, receiving custom
271-
error codes.
272-
273-
The header "x-amzn-query-error" shouldn't be present if it's not
274-
awsQueryCompatible, so added checks for it.
275-
*/
276-
277-
if (httpResponse.HasHeader(QUERY_ERROR_HEADER)) {
278-
auto errorCodeString = httpResponse.GetHeader(QUERY_ERROR_HEADER);
279-
auto locationOfSemicolon = errorCodeString.find_first_of(';');
280-
Aws::String errorCode;
281-
282-
if (locationOfSemicolon != Aws::String::npos) {
283-
errorCode = errorCodeString.substr(0, locationOfSemicolon);
284-
} else {
285-
errorCode = errorCodeString;
286-
}
287-
288-
error.SetExceptionName(errorCode);
289-
}
290-
// check for exception name from payload field 'type'
291-
else if (payloadView.ValueExists(TYPE)) {
292-
// handle missing header and parse code from message
293-
const auto& typeStr = payloadView.GetString(TYPE);
294-
auto locationOfPound = typeStr.find_first_of('#');
295-
if (locationOfPound != Aws::String::npos) {
296-
error.SetExceptionName(typeStr.substr(locationOfPound + 1));
297-
}
298-
}
299-
}
270+
AWS_UNREFERENCED_PARAM(error);
271+
AWS_UNREFERENCED_PARAM(httpResponse);
300272
}

tests/aws-cpp-sdk-monitoring-integration-tests/CloudWatchMonitoringTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <aws/core/utils/memory/AWSMemory.h>
1111
#include <aws/monitoring/CloudWatchClient.h>
1212
#include <aws/monitoring/model/PutMetricDataRequest.h>
13+
#include <aws/monitoring/model/GetDashboardRequest.h>
1314
#include <aws/testing/AwsTestHelpers.h>
1415
#include <aws/testing/TestingEnvironment.h>
1516
#include <gtest/gtest.h>
@@ -91,4 +92,12 @@ TEST_F(CloudWatchMonitoringOperationTest, PutLargeMetricDataTest) {
9192
m_client->PutMetricData(request);
9293
AWS_ASSERT_SUCCESS(outcome);
9394
}
95+
96+
TEST_F(CloudWatchMonitoringOperationTest, DashboardNotFoundShouldParseCorrectly) {
97+
const auto response = m_client->GetDashboard(GetDashboardRequest().WithDashboardName("foo"));
98+
EXPECT_FALSE(response.IsSuccess());
99+
EXPECT_EQ(CloudWatchErrors::DASHBOARD_NOT_FOUND, response.GetError().GetErrorType());
100+
EXPECT_EQ("ResourceNotFound", response.GetError().GetExceptionName());
101+
EXPECT_EQ("Dashboard foo does not exist", response.GetError().GetMessage());
102+
}
94103
} // namespace

0 commit comments

Comments
 (0)