155 159 |
|
156 160 | // If this is an error, defer to the non-streaming parser
|
157 161 | if (!response.status().is_success() && response.status().as_u16() != 200) || force_error {
|
158 162 | return ::std::option::Option::None;
|
159 163 | }
|
160 164 | ::std::option::Option::Some(crate::protocol_serde::type_erase_result(
|
161 165 | crate::protocol_serde::shape_converse_stream::de_converse_stream_http_response(response),
|
162 166 | ))
|
163 167 | }
|
164 168 |
|
165 - | fn deserialize_nonstreaming(
|
169 + | fn deserialize_nonstreaming_with_config(
|
166 170 | &self,
|
167 171 | response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
172 + | _cfg: &::aws_smithy_types::config_bag::ConfigBag,
|
168 173 | ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
|
169 174 | // For streaming operations, we only hit this case if its an error
|
170 175 | let body = response.body().bytes().expect("body loaded");
|
171 - | crate::protocol_serde::type_erase_result(crate::protocol_serde::shape_converse_stream::de_converse_stream_http_error(
|
172 - | response.status().as_u16(),
|
176 + | let status = response.status().as_u16();
|
177 + | let headers = response.headers();
|
178 + | #[allow(unused_mut)]
|
179 + | let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(status, headers, body).map_err(|e| {
|
180 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
181 + | })?;
|
182 + | generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, headers);
|
183 + | let generic = generic_builder.build();
|
184 + | let error_code = match generic.code() {
|
185 + | ::std::option::Option::Some(code) => code,
|
186 + | ::std::option::Option::None => {
|
187 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
188 + | ::aws_smithy_runtime_api::box_error::BoxError::from(crate::operation::converse_stream::ConverseStreamError::unhandled(generic)),
|
189 + | ))
|
190 + | }
|
191 + | };
|
192 + | let _error_message = generic.message().map(|msg| msg.to_owned());
|
193 + | let protocol = _cfg
|
194 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
195 + | .expect("a SharedClientProtocol is required");
|
196 + | let err = match error_code {
|
197 + | "AccessDeniedException" => crate::operation::converse_stream::ConverseStreamError::AccessDeniedException({
|
198 + | let mut tmp = match protocol
|
199 + | .deserialize_response(response, crate::types::error::AccessDeniedException::SCHEMA, _cfg)
|
200 + | .and_then(|mut deser| {
|
201 + | crate::types::error::AccessDeniedException::deserialize_with_response(
|
202 + | &mut *deser,
|
173 203 | response.headers(),
|
204 + | response.status().into(),
|
174 205 | body,
|
206 + | )
|
207 + | }) {
|
208 + | ::std::result::Result::Ok(val) => val,
|
209 + | ::std::result::Result::Err(e) => {
|
210 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
211 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
212 + | ))
|
213 + | }
|
214 + | };
|
215 + | tmp.meta = generic;
|
216 + | if tmp.message.is_none() {
|
217 + | tmp.message = _error_message;
|
218 + | }
|
219 + | tmp
|
220 + | }),
|
221 + | "InternalServerException" => crate::operation::converse_stream::ConverseStreamError::InternalServerException({
|
222 + | let mut tmp = match protocol
|
223 + | .deserialize_response(response, crate::types::error::InternalServerException::SCHEMA, _cfg)
|
224 + | .and_then(|mut deser| {
|
225 + | crate::types::error::InternalServerException::deserialize_with_response(
|
226 + | &mut *deser,
|
227 + | response.headers(),
|
228 + | response.status().into(),
|
229 + | body,
|
230 + | )
|
231 + | }) {
|
232 + | ::std::result::Result::Ok(val) => val,
|
233 + | ::std::result::Result::Err(e) => {
|
234 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
235 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
236 + | ))
|
237 + | }
|
238 + | };
|
239 + | tmp.meta = generic;
|
240 + | if tmp.message.is_none() {
|
241 + | tmp.message = _error_message;
|
242 + | }
|
243 + | tmp
|
244 + | }),
|
245 + | "ModelErrorException" => crate::operation::converse_stream::ConverseStreamError::ModelErrorException({
|
246 + | let mut tmp = match protocol
|
247 + | .deserialize_response(response, crate::types::error::ModelErrorException::SCHEMA, _cfg)
|
248 + | .and_then(|mut deser| {
|
249 + | crate::types::error::ModelErrorException::deserialize_with_response(
|
250 + | &mut *deser,
|
251 + | response.headers(),
|
252 + | response.status().into(),
|
253 + | body,
|
254 + | )
|
255 + | }) {
|
256 + | ::std::result::Result::Ok(val) => val,
|
257 + | ::std::result::Result::Err(e) => {
|
258 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
259 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
260 + | ))
|
261 + | }
|
262 + | };
|
263 + | tmp.meta = generic;
|
264 + | if tmp.message.is_none() {
|
265 + | tmp.message = _error_message;
|
266 + | }
|
267 + | tmp
|
268 + | }),
|
269 + | "ModelNotReadyException" => crate::operation::converse_stream::ConverseStreamError::ModelNotReadyException({
|
270 + | let mut tmp = match protocol
|
271 + | .deserialize_response(response, crate::types::error::ModelNotReadyException::SCHEMA, _cfg)
|
272 + | .and_then(|mut deser| {
|
273 + | crate::types::error::ModelNotReadyException::deserialize_with_response(
|
274 + | &mut *deser,
|
275 + | response.headers(),
|
276 + | response.status().into(),
|
277 + | body,
|
278 + | )
|
279 + | }) {
|
280 + | ::std::result::Result::Ok(val) => val,
|
281 + | ::std::result::Result::Err(e) => {
|
282 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
283 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
284 + | ))
|
285 + | }
|
286 + | };
|
287 + | tmp.meta = generic;
|
288 + | if tmp.message.is_none() {
|
289 + | tmp.message = _error_message;
|
290 + | }
|
291 + | tmp
|
292 + | }),
|
293 + | "ModelTimeoutException" => crate::operation::converse_stream::ConverseStreamError::ModelTimeoutException({
|
294 + | let mut tmp = match protocol
|
295 + | .deserialize_response(response, crate::types::error::ModelTimeoutException::SCHEMA, _cfg)
|
296 + | .and_then(|mut deser| {
|
297 + | crate::types::error::ModelTimeoutException::deserialize_with_response(
|
298 + | &mut *deser,
|
299 + | response.headers(),
|
300 + | response.status().into(),
|
301 + | body,
|
302 + | )
|
303 + | }) {
|
304 + | ::std::result::Result::Ok(val) => val,
|
305 + | ::std::result::Result::Err(e) => {
|
306 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
307 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
308 + | ))
|
309 + | }
|
310 + | };
|
311 + | tmp.meta = generic;
|
312 + | if tmp.message.is_none() {
|
313 + | tmp.message = _error_message;
|
314 + | }
|
315 + | tmp
|
316 + | }),
|
317 + | "ResourceNotFoundException" => crate::operation::converse_stream::ConverseStreamError::ResourceNotFoundException({
|
318 + | let mut tmp = match protocol
|
319 + | .deserialize_response(response, crate::types::error::ResourceNotFoundException::SCHEMA, _cfg)
|
320 + | .and_then(|mut deser| {
|
321 + | crate::types::error::ResourceNotFoundException::deserialize_with_response(
|
322 + | &mut *deser,
|
323 + | response.headers(),
|
324 + | response.status().into(),
|
325 + | body,
|
326 + | )
|
327 + | }) {
|
328 + | ::std::result::Result::Ok(val) => val,
|
329 + | ::std::result::Result::Err(e) => {
|
330 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
331 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
332 + | ))
|
333 + | }
|
334 + | };
|
335 + | tmp.meta = generic;
|
336 + | if tmp.message.is_none() {
|
337 + | tmp.message = _error_message;
|
338 + | }
|
339 + | tmp
|
340 + | }),
|
341 + | "ServiceUnavailableException" => crate::operation::converse_stream::ConverseStreamError::ServiceUnavailableException({
|
342 + | let mut tmp = match protocol
|
343 + | .deserialize_response(response, crate::types::error::ServiceUnavailableException::SCHEMA, _cfg)
|
344 + | .and_then(|mut deser| {
|
345 + | crate::types::error::ServiceUnavailableException::deserialize_with_response(
|
346 + | &mut *deser,
|
347 + | response.headers(),
|
348 + | response.status().into(),
|
349 + | body,
|
350 + | )
|
351 + | }) {
|
352 + | ::std::result::Result::Ok(val) => val,
|
353 + | ::std::result::Result::Err(e) => {
|
354 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
355 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
356 + | ))
|
357 + | }
|
358 + | };
|
359 + | tmp.meta = generic;
|
360 + | if tmp.message.is_none() {
|
361 + | tmp.message = _error_message;
|
362 + | }
|
363 + | tmp
|
364 + | }),
|
365 + | "ThrottlingException" => crate::operation::converse_stream::ConverseStreamError::ThrottlingException({
|
366 + | let mut tmp = match protocol
|
367 + | .deserialize_response(response, crate::types::error::ThrottlingException::SCHEMA, _cfg)
|
368 + | .and_then(|mut deser| {
|
369 + | crate::types::error::ThrottlingException::deserialize_with_response(
|
370 + | &mut *deser,
|
371 + | response.headers(),
|
372 + | response.status().into(),
|
373 + | body,
|
374 + | )
|
375 + | }) {
|
376 + | ::std::result::Result::Ok(val) => val,
|
377 + | ::std::result::Result::Err(e) => {
|
378 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
379 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
380 + | ))
|
381 + | }
|
382 + | };
|
383 + | tmp.meta = generic;
|
384 + | if tmp.message.is_none() {
|
385 + | tmp.message = _error_message;
|
386 + | }
|
387 + | tmp
|
388 + | }),
|
389 + | "ValidationException" => crate::operation::converse_stream::ConverseStreamError::ValidationException({
|
390 + | let mut tmp = match protocol
|
391 + | .deserialize_response(response, crate::types::error::ValidationException::SCHEMA, _cfg)
|
392 + | .and_then(|mut deser| {
|
393 + | crate::types::error::ValidationException::deserialize_with_response(
|
394 + | &mut *deser,
|
395 + | response.headers(),
|
396 + | response.status().into(),
|
397 + | body,
|
398 + | )
|
399 + | }) {
|
400 + | ::std::result::Result::Ok(val) => val,
|
401 + | ::std::result::Result::Err(e) => {
|
402 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
403 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
404 + | ))
|
405 + | }
|
406 + | };
|
407 + | tmp.meta = generic;
|
408 + | if tmp.message.is_none() {
|
409 + | tmp.message = _error_message;
|
410 + | }
|
411 + | tmp
|
412 + | }),
|
413 + | "ModelStreamErrorException" => crate::operation::converse_stream::ConverseStreamError::ModelStreamErrorException({
|
414 + | let mut tmp = match protocol
|
415 + | .deserialize_response(response, crate::types::error::ModelStreamErrorException::SCHEMA, _cfg)
|
416 + | .and_then(|mut deser| {
|
417 + | crate::types::error::ModelStreamErrorException::deserialize_with_response(
|
418 + | &mut *deser,
|
419 + | response.headers(),
|
420 + | response.status().into(),
|
421 + | body,
|
422 + | )
|
423 + | }) {
|
424 + | ::std::result::Result::Ok(val) => val,
|
425 + | ::std::result::Result::Err(e) => {
|
426 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
427 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
428 + | ))
|
429 + | }
|
430 + | };
|
431 + | tmp.meta = generic;
|
432 + | if tmp.message.is_none() {
|
433 + | tmp.message = _error_message;
|
434 + | }
|
435 + | tmp
|
436 + | }),
|
437 + | _ => crate::operation::converse_stream::ConverseStreamError::generic(generic),
|
438 + | };
|
439 + | ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
|
440 + | ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
|
175 441 | ))
|
176 442 | }
|
177 443 | }
|
178 444 | #[derive(Debug)]
|
179 445 | struct ConverseStreamRequestSerializer;
|
180 446 | impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for ConverseStreamRequestSerializer {
|
181 447 | #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
|
182 448 | fn serialize_input(
|
183 449 | &self,
|
184 450 | input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
|
185 451 | _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
|
186 452 | ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
|
187 453 | let input = input
|
188 454 | .downcast::<crate::operation::converse_stream::ConverseStreamInput>()
|
189 455 | .expect("correct type");
|
190 - | let _header_serialization_settings = _cfg
|
191 - | .load::<crate::serialization_settings::HeaderSerializationSettings>()
|
192 - | .cloned()
|
193 - | .unwrap_or_default();
|
194 - | let mut request_builder = {
|
195 - | #[allow(clippy::uninlined_format_args)]
|
196 - | fn uri_base(
|
197 - | _input: &crate::operation::converse_stream::ConverseStreamInput,
|
198 - | output: &mut ::std::string::String,
|
199 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
|
200 - | use ::std::fmt::Write as _;
|
201 - | let input_1 = &_input.model_id;
|
202 - | let input_1 = input_1
|
203 - | .as_ref()
|
204 - | .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("model_id", "cannot be empty or unset"))?;
|
205 - | let model_id = ::aws_smithy_http::label::fmt_string(input_1, ::aws_smithy_http::label::EncodingStrategy::Default);
|
206 - | if model_id.is_empty() {
|
207 - | return ::std::result::Result::Err(::aws_smithy_types::error::operation::BuildError::missing_field(
|
208 - | "model_id",
|
209 - | "cannot be empty or unset",
|
210 - | ));
|
456 + | let protocol = _cfg
|
457 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
458 + | .expect("a SharedClientProtocol is required");
|
459 + | if protocol.supports_http_bindings() {
|
460 + | let mut request = protocol
|
461 + | .serialize_body(&input, ConverseStream::INPUT_SCHEMA, "", _cfg)
|
462 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
463 + | {
|
464 + | let mut uri = "/model/{modelId}/converse-stream".to_string();
|
465 + | let mut query_params: Vec<(String, String)> = Vec::new();
|
466 + | if let Some(ref val) = input.model_id {
|
467 + | uri = uri.replace("{modelId}", &::aws_smithy_schema::http_protocol::percent_encode(&val.to_string()));
|
468 + | }
|
469 + | if !query_params.is_empty() {
|
470 + | uri.push(if uri.contains('?') { '&' } else { '?' });
|
471 + | let pairs: Vec<String> = query_params
|
472 + | .iter()
|
473 + | .map(|(k, v)| {
|
474 + | format!(
|
475 + | "{}={}",
|
476 + | ::aws_smithy_schema::http_protocol::percent_encode(k),
|
477 + | ::aws_smithy_schema::http_protocol::percent_encode(v)
|
478 + | )
|
479 + | })
|
480 + | .collect();
|
481 + | uri.push_str(&pairs.join("&"));
|
211 482 | }
|
212 - | ::std::write!(output, "/model/{modelId}/converse-stream", modelId = model_id).expect("formatting should succeed");
|
213 - | ::std::result::Result::Ok(())
|
483 + | request.set_uri(uri.as_str()).expect("valid URI");
|
214 484 | }
|
215 - | #[allow(clippy::unnecessary_wraps)]
|
216 - | fn update_http_builder(
|
217 - | input: &crate::operation::converse_stream::ConverseStreamInput,
|
218 - | builder: ::http_1x::request::Builder,
|
219 - | ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
|
220 - | let mut uri = ::std::string::String::new();
|
221 - | uri_base(input, &mut uri)?;
|
222 - | ::std::result::Result::Ok(builder.method("POST").uri(uri))
|
223 - | }
|
224 - | let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
|
225 - | builder = _header_serialization_settings.set_default_header(builder, ::http_1x::header::CONTENT_TYPE, "application/json");
|
226 - | builder
|
227 - | };
|
228 - | let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_converse_stream::ser_converse_stream_input(&input)?);
|
229 - | if let Some(content_length) = body.content_length() {
|
230 - | let content_length = content_length.to_string();
|
231 - | request_builder = _header_serialization_settings.set_default_header(request_builder, ::http_1x::header::CONTENT_LENGTH, &content_length);
|
485 + |
|
486 + | return ::std::result::Result::Ok(request);
|
487 + | } else {
|
488 + | let mut request = protocol
|
489 + | .serialize_request(&input, ConverseStream::INPUT_SCHEMA, "", _cfg)
|
490 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
491 + |
|
492 + | return ::std::result::Result::Ok(request);
|
232 493 | }
|
233 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
234 494 | }
|
235 495 | }
|
236 496 | #[derive(Debug)]
|
237 497 | struct ConverseStreamEndpointParamsInterceptor;
|
238 498 |
|
239 499 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for ConverseStreamEndpointParamsInterceptor {
|
240 500 | fn name(&self) -> &'static str {
|
241 501 | "ConverseStreamEndpointParamsInterceptor"
|
242 502 | }
|
243 503 |
|