AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
JsonOutcomeSerializer.h
1
5#pragma once
6#include <aws/core/AmazonWebServiceResult.h>
7#include <aws/core/client/AWSError.h>
8#include <aws/core/utils/Outcome.h>
9#include <aws/core/utils/json/JsonSerializer.h>
10#include <smithy/tracing/TracingUtils.h>
11#include <smithy/tracing/TelemetryProvider.h>
12
13namespace smithy
14{
15 namespace client
16 {
24
26 {
27 public:
28 explicit JsonOutcomeSerializer(const std::shared_ptr<TelemetryProvider>& telemetryProvider)
29 : m_telemetryProvider(telemetryProvider)
30 {
31 }
32
34 JsonOutcomeSerializer(JsonOutcomeSerializer&& other) noexcept = default;
37 virtual ~JsonOutcomeSerializer() = default;
38
40 const Aws::String& serviceName,
41 const Aws::String& requestName) const
42 {
43 if (!httpOutcome.IsSuccess())
44 {
45 return TracingUtils::MakeCallWithTiming<JsonOutcome>(
46 [&]() -> JsonOutcome {
47 return JsonOutcome{std::move(httpOutcome)};
48 },
50 *m_telemetryProvider->getMeter(serviceName, {}),
53 }
54
55 if (httpOutcome.GetResult()->GetResponseBody().good() &&
56 httpOutcome.GetResult()->GetResponseBody().tellp() > 0)
57 {
58 JsonValue jsonValue(httpOutcome.GetResult()->GetResponseBody());
59 if (!jsonValue.WasParseSuccessful()) {
60 return TracingUtils::MakeCallWithTiming<JsonOutcome>(
61 [&]() -> JsonOutcome {
62 return JsonOutcome{AWSError(CoreErrors::UNKNOWN,
63 "Json Parser Error",
64 jsonValue.GetErrorMessage(),
65 false)};
66 },
68 *m_telemetryProvider->getMeter(serviceName, {}),
71 }
72
73 return TracingUtils::MakeCallWithTiming<JsonOutcome>(
74 [&]() -> JsonOutcome {
75 return JsonOutcome{Aws::AmazonWebServiceResult<JsonValue>(std::move(jsonValue),
76 httpOutcome.GetResult()->GetHeaders(),
77 httpOutcome.GetResult()->GetResponseCode())};
78 },
80 *m_telemetryProvider->getMeter(serviceName, {}),
83 }
84
85 return TracingUtils::MakeCallWithTiming<JsonOutcome>(
86 [&]() -> JsonOutcome {
88 httpOutcome.GetResult()->GetHeaders())};
89 },
91 *m_telemetryProvider->getMeter(serviceName, {}),
94 }
95
96 private:
97 std::shared_ptr<TelemetryProvider> m_telemetryProvider;
98 };
99 } // namespace client
100} // namespace smithy
const Aws::String & GetErrorMessage() const
JsonOutcomeSerializer & operator=(JsonOutcomeSerializer &&other) noexcept=default
JsonOutcomeSerializer & operator=(const JsonOutcomeSerializer &other)=delete
JsonOutcomeSerializer(const std::shared_ptr< TelemetryProvider > &telemetryProvider)
JsonOutcome Deserialize(HttpResponseOutcome &&httpOutcome, const Aws::String &serviceName, const Aws::String &requestName) const
JsonOutcomeSerializer(const JsonOutcomeSerializer &other)=delete
JsonOutcomeSerializer(JsonOutcomeSerializer &&other) noexcept=default
static const char SMITHY_CLIENT_DESERIALIZATION_METRIC[]
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
Aws::Client::AWSError< CoreErrors > AWSError
Aws::Utils::Json::JsonValue JsonValue