145 151 |
|
146 152 | // If this is an error, defer to the non-streaming parser
|
147 153 | if (!response.status().is_success() && response.status().as_u16() != 200) || force_error {
|
148 154 | return ::std::option::Option::None;
|
149 155 | }
|
150 156 | ::std::option::Option::Some(crate::protocol_serde::type_erase_result(
|
151 157 | crate::protocol_serde::shape_duplex_stream_with_initial_messages::de_duplex_stream_with_initial_messages_http_response(response),
|
152 158 | ))
|
153 159 | }
|
154 160 |
|
155 - | fn deserialize_nonstreaming(
|
161 + | fn deserialize_nonstreaming_with_config(
|
156 162 | &self,
|
157 163 | response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
164 + | _cfg: &::aws_smithy_types::config_bag::ConfigBag,
|
158 165 | ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
|
159 166 | // For streaming operations, we only hit this case if its an error
|
160 167 | let body = response.body().bytes().expect("body loaded");
|
161 - | crate::protocol_serde::type_erase_result(
|
162 - | crate::protocol_serde::shape_duplex_stream_with_initial_messages::de_duplex_stream_with_initial_messages_http_error(
|
163 - | response.status().as_u16(),
|
168 + | let status = response.status().as_u16();
|
169 + | let headers = response.headers();
|
170 + | #[allow(unused_mut)]
|
171 + | let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(status, headers, body).map_err(|e| {
|
172 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
173 + | })?;
|
174 + |
|
175 + | let generic = generic_builder.build();
|
176 + | let error_code = match generic.code() {
|
177 + | ::std::option::Option::Some(code) => code,
|
178 + | ::std::option::Option::None => {
|
179 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
180 + | ::aws_smithy_runtime_api::box_error::BoxError::from(
|
181 + | crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesError::unhandled(generic),
|
182 + | ),
|
183 + | ))
|
184 + | }
|
185 + | };
|
186 + | let _error_message = generic.message().map(|msg| msg.to_owned());
|
187 + | let protocol = _cfg
|
188 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
189 + | .expect("a SharedClientProtocol is required");
|
190 + | let err = match error_code {
|
191 + | "ServiceUnavailableError" => {
|
192 + | crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesError::ServiceUnavailableError({
|
193 + | let mut tmp = match protocol
|
194 + | .deserialize_response(response, crate::types::error::ServiceUnavailableError::SCHEMA, _cfg)
|
195 + | .and_then(|mut deser| {
|
196 + | crate::types::error::ServiceUnavailableError::deserialize_with_response(
|
197 + | &mut *deser,
|
164 198 | response.headers(),
|
199 + | response.status().into(),
|
165 200 | body,
|
166 - | ),
|
167 201 | )
|
202 + | }) {
|
203 + | ::std::result::Result::Ok(val) => val,
|
204 + | ::std::result::Result::Err(e) => {
|
205 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
206 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
207 + | ))
|
208 + | }
|
209 + | };
|
210 + | tmp.meta = generic;
|
211 + | if tmp.message.is_none() {
|
212 + | tmp.message = _error_message;
|
213 + | }
|
214 + | tmp
|
215 + | })
|
216 + | }
|
217 + | "ErrorEvent" => crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesError::ErrorEvent({
|
218 + | let mut tmp = match protocol
|
219 + | .deserialize_response(response, crate::types::error::ErrorEvent::SCHEMA, _cfg)
|
220 + | .and_then(|mut deser| {
|
221 + | crate::types::error::ErrorEvent::deserialize_with_response(&mut *deser, response.headers(), response.status().into(), body)
|
222 + | }) {
|
223 + | ::std::result::Result::Ok(val) => val,
|
224 + | ::std::result::Result::Err(e) => {
|
225 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
226 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
227 + | ))
|
228 + | }
|
229 + | };
|
230 + | tmp.meta = generic;
|
231 + | if tmp.message.is_none() {
|
232 + | tmp.message = _error_message;
|
233 + | }
|
234 + | tmp
|
235 + | }),
|
236 + | _ => crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesError::generic(generic),
|
237 + | };
|
238 + | ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
|
239 + | ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
|
240 + | ))
|
168 241 | }
|
169 242 | }
|
170 243 | #[derive(Debug)]
|
171 244 | struct DuplexStreamWithInitialMessagesRequestSerializer;
|
172 245 | impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for DuplexStreamWithInitialMessagesRequestSerializer {
|
173 246 | #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
|
174 247 | fn serialize_input(
|
175 248 | &self,
|
176 249 | input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
|
177 250 | _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
|
178 251 | ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
|
179 252 | let input = input
|
180 253 | .downcast::<crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesInput>()
|
181 254 | .expect("correct type");
|
182 - | let _header_serialization_settings = _cfg
|
183 - | .load::<crate::serialization_settings::HeaderSerializationSettings>()
|
184 - | .cloned()
|
185 - | .unwrap_or_default();
|
186 - | let mut request_builder = {
|
187 - | #[allow(clippy::uninlined_format_args)]
|
188 - | fn uri_base(
|
189 - | _input: &crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesInput,
|
190 - | output: &mut ::std::string::String,
|
191 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
|
192 - | use ::std::fmt::Write as _;
|
193 - | ::std::write!(output, "/DuplexStreamWithInitialMessages").expect("formatting should succeed");
|
194 - | ::std::result::Result::Ok(())
|
195 - | }
|
196 - | #[allow(clippy::unnecessary_wraps)]
|
197 - | fn update_http_builder(
|
198 - | input: &crate::operation::duplex_stream_with_initial_messages::DuplexStreamWithInitialMessagesInput,
|
199 - | builder: ::http_1x::request::Builder,
|
200 - | ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
|
201 - | let mut uri = ::std::string::String::new();
|
202 - | uri_base(input, &mut uri)?;
|
203 - | let builder = crate::protocol_serde::shape_duplex_stream_with_initial_messages::ser_duplex_stream_with_initial_messages_headers(
|
204 - | input, builder,
|
205 - | )?;
|
206 - | ::std::result::Result::Ok(builder.method("POST").uri(uri))
|
207 - | }
|
208 - | let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
|
209 - | builder =
|
210 - | _header_serialization_settings.set_default_header(builder, ::http_1x::header::CONTENT_TYPE, "application/vnd.amazon.eventstream");
|
211 - | builder
|
212 - | };
|
213 - | let body = ::aws_smithy_types::body::SdkBody::from({
|
255 + | let protocol = _cfg
|
256 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
257 + | .expect("a SharedClientProtocol is required");
|
258 + | let mut request = protocol
|
259 + | .serialize_request(&input, DuplexStreamWithInitialMessages::INPUT_SCHEMA, "", _cfg)
|
260 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
261 + | *request.body_mut() = ::aws_smithy_types::body::SdkBody::from({
|
214 262 | let error_marshaller = crate::event_stream_serde::EventStreamErrorMarshaller::new();
|
215 263 | let marshaller = crate::event_stream_serde::EventStreamMarshaller::new();
|
216 264 | let (signer, signer_sender) = ::aws_smithy_eventstream::frame::DeferredSigner::new();
|
217 265 | _cfg.interceptor_state().store_put(signer_sender);
|
218 266 | ::aws_smithy_types::body::SdkBody::from_body_1_x(::http_body_util::StreamBody::new(input.stream.into_body_stream(
|
219 267 | marshaller,
|
220 268 | error_marshaller,
|
221 269 | signer,
|
222 270 | )))
|
223 271 | });
|
224 - | if let Some(content_length) = body.content_length() {
|
225 - | let content_length = content_length.to_string();
|
226 - | request_builder = _header_serialization_settings.set_default_header(request_builder, ::http_1x::header::CONTENT_LENGTH, &content_length);
|
227 - | }
|
228 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
272 + | // The protocol may have set Content-Length based on the initial empty body.
|
273 + | // Remove it since the event stream body has unknown length.
|
274 + | request.headers_mut().remove("Content-Length");
|
275 + | request.headers_mut().insert("Content-Type", "application/vnd.amazon.eventstream");
|
276 + |
|
277 + | return ::std::result::Result::Ok(request);
|
229 278 | }
|
230 279 | }
|
231 280 | #[derive(Debug)]
|
232 281 | struct DuplexStreamWithInitialMessagesEndpointParamsInterceptor;
|
233 282 |
|
234 283 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for DuplexStreamWithInitialMessagesEndpointParamsInterceptor {
|
235 284 | fn name(&self) -> &'static str {
|
236 285 | "DuplexStreamWithInitialMessagesEndpointParamsInterceptor"
|
237 286 | }
|
238 287 |
|