180 225 | }
|
181 226 | #[derive(Debug)]
|
182 227 | struct GreetingWithErrorsResponseDeserializer;
|
183 228 | impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for GreetingWithErrorsResponseDeserializer {
|
184 229 | fn deserialize_nonstreaming_with_config(
|
185 230 | &self,
|
186 231 | response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
187 232 | _cfg: &::aws_smithy_types::config_bag::ConfigBag,
|
188 233 | ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
|
189 234 | let (success, status) = (response.status().is_success(), response.status().as_u16());
|
190 - | let headers = response.headers();
|
235 + | // Load body and headers BEFORE BeforeParseResponse so customizations
|
236 + | // (e.g., S3's `body_is_error` check that detects errors returned with
|
237 + | // HTTP 200) can inspect them. The legacy non-streaming path also
|
238 + | // loads `body` before firing this hook.
|
191 239 | let body = response.body().bytes().expect("body loaded");
|
240 + | let headers = response.headers();
|
192 241 | #[allow(unused_mut)]
|
193 242 | let mut force_error = false;
|
194 243 |
|
195 - | let parse_result = if !success && status != 200 || force_error {
|
196 - | crate::protocol_serde::shape_greeting_with_errors::de_greeting_with_errors_http_error(status, headers, body)
|
197 - | } else {
|
198 - | crate::protocol_serde::shape_greeting_with_errors::de_greeting_with_errors_http_response(status, headers, body)
|
244 + | if !success && status != 200 || force_error {
|
245 + | let protocol = _cfg
|
246 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
247 + | .expect("a SharedClientProtocol is required");
|
248 + | #[allow(unused_mut)]
|
249 + | let mut generic_builder = protocol.parse_error_metadata(response, _cfg).map_err(|e| {
|
250 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
251 + | })?;
|
252 + |
|
253 + | let generic = generic_builder.build();
|
254 + | let error_code = match generic.code() {
|
255 + | ::std::option::Option::Some(code) => code,
|
256 + | ::std::option::Option::None => {
|
257 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
258 + | ::aws_smithy_runtime_api::box_error::BoxError::from(
|
259 + | crate::operation::greeting_with_errors::GreetingWithErrorsError::unhandled(generic),
|
260 + | ),
|
261 + | ))
|
262 + | }
|
263 + | };
|
264 + | let _error_message = generic.message().map(|msg| msg.to_owned());
|
265 + | let err = match error_code {
|
266 + | "InvalidGreeting" => crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting({
|
267 + | let mut tmp = match protocol.deserialize_error_response(response, _cfg).and_then(|mut deser| {
|
268 + | crate::types::error::InvalidGreeting::deserialize_with_response(
|
269 + | &mut *deser,
|
270 + | response.headers(),
|
271 + | response.status().into(),
|
272 + | body,
|
273 + | )
|
274 + | }) {
|
275 + | ::std::result::Result::Ok(val) => val,
|
276 + | ::std::result::Result::Err(e) => {
|
277 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
278 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
279 + | ))
|
280 + | }
|
199 281 | };
|
200 - | crate::protocol_serde::type_erase_result(parse_result)
|
282 + | tmp.meta = generic;
|
283 + | if tmp.message.is_none() {
|
284 + | tmp.message = _error_message;
|
285 + | }
|
286 + | tmp
|
287 + | }),
|
288 + | "ComplexError" => crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError({
|
289 + | let mut tmp = match protocol.deserialize_error_response(response, _cfg).and_then(|mut deser| {
|
290 + | crate::types::error::ComplexError::deserialize_with_response(&mut *deser, response.headers(), response.status().into(), body)
|
291 + | }) {
|
292 + | ::std::result::Result::Ok(val) => val,
|
293 + | ::std::result::Result::Err(e) => {
|
294 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
295 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
296 + | ))
|
297 + | }
|
298 + | };
|
299 + | tmp.meta = generic;
|
300 + | if tmp.message.is_none() {
|
301 + | tmp.message = _error_message;
|
302 + | }
|
303 + | tmp
|
304 + | }),
|
305 + | "FooError" => crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError({
|
306 + | let mut tmp = match protocol.deserialize_error_response(response, _cfg).and_then(|mut deser| {
|
307 + | crate::types::error::FooError::deserialize_with_response(&mut *deser, response.headers(), response.status().into(), body)
|
308 + | }) {
|
309 + | ::std::result::Result::Ok(val) => val,
|
310 + | ::std::result::Result::Err(e) => {
|
311 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
312 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
313 + | ))
|
314 + | }
|
315 + | };
|
316 + | tmp.meta = generic;
|
317 + | if tmp.message.is_none() {
|
318 + | tmp.message = _error_message;
|
319 + | }
|
320 + | tmp
|
321 + | }),
|
322 + | _ => {
|
323 + | // Registry-backed, operation-scoped reification of an error whose
|
324 + | // code this operation does not model directly: the operation's own
|
325 + | // error registry is consulted first, then the lookup widens to the
|
326 + | // service-wide error registry. On a hit, the reified error is attached
|
327 + | // as the source of the returned unhandled error while its metadata
|
328 + | // (code, message, request id) is preserved; on a miss the generic
|
329 + | // error is returned unchanged.
|
330 + | match protocol
|
331 + | .deserialize_error_response(response, _cfg)
|
332 + | .ok()
|
333 + | .and_then(|mut deser| {
|
334 + | ::aws_smithy_schema::registry::reify_error(
|
335 + | crate::operation::greeting_with_errors::error_registry::REGISTRY
|
336 + | .or(&crate::error_type_registry::REGISTRY),
|
337 + | error_code,
|
338 + | &mut *deser,
|
339 + | )
|
340 + | }) {
|
341 + | ::std::option::Option::Some(source) => <crate::operation::greeting_with_errors::GreetingWithErrorsError as ::aws_smithy_runtime_api::client::result::CreateUnhandledError>::create_unhandled_error(source, ::std::option::Option::Some(generic)),
|
342 + | ::std::option::Option::None => crate::operation::greeting_with_errors::GreetingWithErrorsError::generic(generic),
|
343 + | }
|
344 + | }
|
345 + | };
|
346 + | ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
|
347 + | ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
|
348 + | ))
|
349 + | } else {
|
350 + | let protocol = _cfg
|
351 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
352 + | .expect("a SharedClientProtocol is required");
|
353 + | let mut deser = protocol
|
354 + | .deserialize_response(response, GreetingWithErrors::OUTPUT_SCHEMA, _cfg)
|
355 + | .map_err(|e| {
|
356 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
357 + | })?;
|
358 + | // body and headers are already in scope from the top of the function;
|
359 + | // alias `headers` as `_response_headers` so MutateOutput
|
360 + | // customizations have a stable name to read from.
|
361 + | let _response_headers = headers;
|
362 + | #[allow(unused_mut)]
|
363 + | let mut output = crate::operation::greeting_with_errors::GreetingWithErrorsOutput::deserialize_with_response(
|
364 + | &mut *deser,
|
365 + | _response_headers,
|
366 + | response.status().into(),
|
367 + | body,
|
368 + | )
|
369 + | .map_err(|e| {
|
370 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
371 + | })?;
|
372 + |
|
373 + | ::std::result::Result::Ok(::aws_smithy_runtime_api::client::interceptors::context::Output::erase(output))
|
374 + | }
|
201 375 | }
|
202 376 | }
|
203 377 | #[derive(Debug)]
|
204 378 | struct GreetingWithErrorsRequestSerializer;
|
205 379 | impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for GreetingWithErrorsRequestSerializer {
|
206 380 | #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
|
207 381 | fn serialize_input(
|
208 382 | &self,
|
209 383 | input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
|
210 384 | _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
|
211 385 | ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
|
212 386 | let input = input
|
213 387 | .downcast::<crate::operation::greeting_with_errors::GreetingWithErrorsInput>()
|
214 388 | .expect("correct type");
|
215 - | let _header_serialization_settings = _cfg
|
216 - | .load::<crate::serialization_settings::HeaderSerializationSettings>()
|
217 - | .cloned()
|
218 - | .unwrap_or_default();
|
219 - | let mut request_builder = {
|
220 - | #[allow(clippy::uninlined_format_args)]
|
221 - | fn uri_base(
|
222 - | _input: &crate::operation::greeting_with_errors::GreetingWithErrorsInput,
|
223 - | output: &mut ::std::string::String,
|
224 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
|
225 - | use ::std::fmt::Write as _;
|
226 - | ::std::write!(output, "/").expect("formatting should succeed");
|
227 - | ::std::result::Result::Ok(())
|
228 - | }
|
229 - | #[allow(clippy::unnecessary_wraps)]
|
230 - | fn update_http_builder(
|
231 - | input: &crate::operation::greeting_with_errors::GreetingWithErrorsInput,
|
232 - | builder: ::http_1x::request::Builder,
|
233 - | ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
|
234 - | let mut uri = ::std::string::String::new();
|
235 - | uri_base(input, &mut uri)?;
|
236 - | ::std::result::Result::Ok(builder.method("POST").uri(uri))
|
237 - | }
|
238 - | let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
|
239 - | builder = _header_serialization_settings.set_default_header(builder, ::http_1x::header::CONTENT_TYPE, "application/x-amz-json-1.0");
|
240 - | builder = _header_serialization_settings.set_default_header(
|
241 - | builder,
|
242 - | ::http_1x::header::HeaderName::from_static("x-amz-target"),
|
243 - | "JsonRpc10.GreetingWithErrors",
|
244 - | );
|
245 - | builder
|
246 - | };
|
247 - | let body =
|
248 - | ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_greeting_with_errors::ser_greeting_with_errors_input(&input)?);
|
249 - | if let Some(content_length) = body.content_length() {
|
250 - | let content_length = content_length.to_string();
|
251 - | request_builder = _header_serialization_settings.set_default_header(request_builder, ::http_1x::header::CONTENT_LENGTH, &content_length);
|
252 - | }
|
253 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
389 + |
|
390 + | let protocol = _cfg
|
391 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
392 + | .expect("a SharedClientProtocol is required");
|
393 + | let mut request = protocol
|
394 + | .serialize_request(&input, GreetingWithErrors::INPUT_SCHEMA, "/", _cfg)
|
395 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
396 + |
|
397 + | return ::std::result::Result::Ok(request);
|
254 398 | }
|
255 399 | }
|
256 400 | #[derive(Debug)]
|
257 401 | struct GreetingWithErrorsEndpointParamsInterceptor;
|
258 402 |
|
259 403 | #[::aws_smithy_runtime_api::client::interceptors::dyn_dispatch_hint]
|
260 404 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for GreetingWithErrorsEndpointParamsInterceptor {
|
261 405 | fn name(&self) -> &'static str {
|
262 406 | "GreetingWithErrorsEndpointParamsInterceptor"
|
263 407 | }
|
316 460 |
|
317 461 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
318 462 | let config = op.config().expect("the operation has config");
|
319 463 | let de = config
|
320 464 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
321 465 | .expect("the config must have a deserializer");
|
322 466 |
|
323 467 | // Build a config bag with the protocol for schema-based deserialization
|
324 468 | #[allow(unused_mut)]
|
325 469 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
470 + | {
|
471 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
472 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
473 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
474 + | ));
|
475 + | test_cfg.push_shared_layer(layer.freeze());
|
476 + | }
|
326 477 |
|
327 478 | let parsed = de.deserialize_streaming(&mut http_response);
|
328 479 | let parsed = parsed.unwrap_or_else(|| {
|
329 480 | let http_response = http_response.map(|body| {
|
330 481 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
331 482 | body.bytes().unwrap(),
|
332 483 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
333 484 | )))
|
334 485 | });
|
335 486 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
336 487 | });
|
337 488 | let parsed = parsed.expect_err("should be error response");
|
338 489 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
339 490 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
340 491 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::InvalidGreeting(parsed) = parsed {
|
341 492 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
342 493 | } else {
|
343 494 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
344 495 | }
|
345 496 | }
|
346 497 |
|
347 498 | /// Parses a complex error with no message member
|
348 499 | /// Test ID: AwsJson10ComplexError
|
349 500 | #[::tokio::test]
|
350 501 | #[::tracing_test::traced_test]
|
351 502 | async fn aws_json10_complex_error_response() {
|
352 503 | let expected_output = crate::types::error::ComplexError::builder()
|
353 504 | .set_top_level(::std::option::Option::Some("Top level".to_owned()))
|
354 505 | .set_nested(::std::option::Option::Some(
|
355 506 | crate::types::ComplexNestedErrorData::builder()
|
356 507 | .set_foo(::std::option::Option::Some("bar".to_owned()))
|
357 508 | .build(),
|
358 509 | ))
|
359 510 | .build();
|
360 511 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
361 512 | .header("Content-Type", "application/x-amz-json-1.0")
|
362 513 | .status(400)
|
363 514 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"aws.protocoltests.json10#ComplexError\",\n \"TopLevel\": \"Top level\",\n \"Nested\": {\n \"Foo\": \"bar\"\n }\n}"))
|
364 515 | .unwrap()
|
365 516 | ).unwrap();
|
366 517 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
367 518 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
368 519 |
|
369 520 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
370 521 | let config = op.config().expect("the operation has config");
|
371 522 | let de = config
|
372 523 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
373 524 | .expect("the config must have a deserializer");
|
374 525 |
|
375 526 | // Build a config bag with the protocol for schema-based deserialization
|
376 527 | #[allow(unused_mut)]
|
377 528 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
529 + | {
|
530 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
531 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
532 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
533 + | ));
|
534 + | test_cfg.push_shared_layer(layer.freeze());
|
535 + | }
|
378 536 |
|
379 537 | let parsed = de.deserialize_streaming(&mut http_response);
|
380 538 | let parsed = parsed.unwrap_or_else(|| {
|
381 539 | let http_response = http_response.map(|body| {
|
382 540 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
383 541 | body.bytes().unwrap(),
|
384 542 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
385 543 | )))
|
386 544 | });
|
387 545 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
388 546 | });
|
389 547 | let parsed = parsed.expect_err("should be error response");
|
390 548 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
391 549 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
392 550 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
393 551 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
394 552 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
395 553 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
396 554 | } else {
|
397 555 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
398 556 | }
|
399 557 | }
|
400 558 |
|
401 559 | /// Parses a complex error with an empty body
|
402 560 | /// Test ID: AwsJson10EmptyComplexError
|
403 561 | #[::tokio::test]
|
404 562 | #[::tracing_test::traced_test]
|
405 563 | async fn aws_json10_empty_complex_error_response() {
|
406 564 | let expected_output = crate::types::error::ComplexError::builder().build();
|
407 565 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
408 566 | ::http_1x::response::Builder::new()
|
409 567 | .header("Content-Type", "application/x-amz-json-1.0")
|
410 568 | .status(400)
|
411 569 | .body(::aws_smithy_types::body::SdkBody::from(
|
412 570 | "{\n \"__type\": \"aws.protocoltests.json10#ComplexError\"\n}",
|
413 571 | ))
|
414 572 | .unwrap(),
|
415 573 | )
|
416 574 | .unwrap();
|
417 575 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
418 576 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
419 577 |
|
420 578 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
421 579 | let config = op.config().expect("the operation has config");
|
422 580 | let de = config
|
423 581 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
424 582 | .expect("the config must have a deserializer");
|
425 583 |
|
426 584 | // Build a config bag with the protocol for schema-based deserialization
|
427 585 | #[allow(unused_mut)]
|
428 586 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
587 + | {
|
588 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
589 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
590 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
591 + | ));
|
592 + | test_cfg.push_shared_layer(layer.freeze());
|
593 + | }
|
429 594 |
|
430 595 | let parsed = de.deserialize_streaming(&mut http_response);
|
431 596 | let parsed = parsed.unwrap_or_else(|| {
|
432 597 | let http_response = http_response.map(|body| {
|
433 598 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
434 599 | body.bytes().unwrap(),
|
435 600 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
436 601 | )))
|
437 602 | });
|
438 603 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
439 604 | });
|
440 605 | let parsed = parsed.expect_err("should be error response");
|
441 606 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
442 607 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
443 608 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::ComplexError(parsed) = parsed {
|
444 609 | ::pretty_assertions::assert_eq!(parsed.top_level, expected_output.top_level, "Unexpected value for `top_level`");
|
445 610 | ::pretty_assertions::assert_eq!(parsed.nested, expected_output.nested, "Unexpected value for `nested`");
|
446 611 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
447 612 | } else {
|
448 613 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
449 614 | }
|
450 615 | }
|
451 616 |
|
452 617 | /// Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
|
453 618 | /// Test ID: AwsJson10FooErrorUsingXAmznErrorType
|
454 619 | #[::tokio::test]
|
455 620 | #[::tracing_test::traced_test]
|
456 621 | async fn aws_json10_foo_error_using_x_amzn_error_type_response() {
|
457 622 | let expected_output = crate::types::error::FooError::builder().build();
|
458 623 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
459 624 | ::http_1x::response::Builder::new()
|
460 625 | .header("X-Amzn-Errortype", "FooError")
|
461 626 | .status(500)
|
462 627 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
463 628 | .unwrap(),
|
464 629 | )
|
465 630 | .unwrap();
|
466 631 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
467 632 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
468 633 |
|
469 634 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
470 635 | let config = op.config().expect("the operation has config");
|
471 636 | let de = config
|
472 637 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
473 638 | .expect("the config must have a deserializer");
|
474 639 |
|
475 640 | // Build a config bag with the protocol for schema-based deserialization
|
476 641 | #[allow(unused_mut)]
|
477 642 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
643 + | {
|
644 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
645 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
646 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
647 + | ));
|
648 + | test_cfg.push_shared_layer(layer.freeze());
|
649 + | }
|
478 650 |
|
479 651 | let parsed = de.deserialize_streaming(&mut http_response);
|
480 652 | let parsed = parsed.unwrap_or_else(|| {
|
481 653 | let http_response = http_response.map(|body| {
|
482 654 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
483 655 | body.bytes().unwrap(),
|
484 656 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
485 657 | )))
|
486 658 | });
|
487 659 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
488 660 | });
|
489 661 | let parsed = parsed.expect_err("should be error response");
|
490 662 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
491 663 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
492 664 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
493 665 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
494 666 | } else {
|
495 667 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
496 668 | }
|
497 669 | }
|
498 670 |
|
499 671 | /// Some X-Amzn-Errortype headers contain URLs. Clients need to split the URL on ':' and take only the first half of the string. For example, 'ValidationException:http://internal.amazon.com/coral/com.amazon.coral.validate/'
|
500 672 | /// is to be interpreted as 'ValidationException'.
|
501 673 | ///
|
502 674 | /// For an example service see Amazon Polly.
|
503 675 | /// Test ID: AwsJson10FooErrorUsingXAmznErrorTypeWithUri
|
504 676 | #[::tokio::test]
|
505 677 | #[::tracing_test::traced_test]
|
506 678 | async fn aws_json10_foo_error_using_x_amzn_error_type_with_uri_response() {
|
507 679 | let expected_output = crate::types::error::FooError::builder().build();
|
508 680 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
509 681 | ::http_1x::response::Builder::new()
|
510 682 | .header("X-Amzn-Errortype", "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/")
|
511 683 | .status(500)
|
512 684 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
513 685 | .unwrap(),
|
514 686 | )
|
515 687 | .unwrap();
|
516 688 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
517 689 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
518 690 |
|
519 691 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
520 692 | let config = op.config().expect("the operation has config");
|
521 693 | let de = config
|
522 694 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
523 695 | .expect("the config must have a deserializer");
|
524 696 |
|
525 697 | // Build a config bag with the protocol for schema-based deserialization
|
526 698 | #[allow(unused_mut)]
|
527 699 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
700 + | {
|
701 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
702 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
703 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
704 + | ));
|
705 + | test_cfg.push_shared_layer(layer.freeze());
|
706 + | }
|
528 707 |
|
529 708 | let parsed = de.deserialize_streaming(&mut http_response);
|
530 709 | let parsed = parsed.unwrap_or_else(|| {
|
531 710 | let http_response = http_response.map(|body| {
|
532 711 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
533 712 | body.bytes().unwrap(),
|
534 713 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
535 714 | )))
|
536 715 | });
|
537 716 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
538 717 | });
|
539 718 | let parsed = parsed.expect_err("should be error response");
|
540 719 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
541 720 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
542 721 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
543 722 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
544 723 | } else {
|
545 724 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
546 725 | }
|
547 726 | }
|
548 727 |
|
549 728 | /// X-Amzn-Errortype might contain a URL and a namespace. Client should extract only the shape name. This is a pathalogical case that might not actually happen in any deployed AWS service.
|
550 729 | /// Test ID: AwsJson10FooErrorUsingXAmznErrorTypeWithUriAndNamespace
|
551 730 | #[::tokio::test]
|
552 731 | #[::tracing_test::traced_test]
|
553 732 | async fn aws_json10_foo_error_using_x_amzn_error_type_with_uri_and_namespace_response() {
|
554 733 | let expected_output = crate::types::error::FooError::builder().build();
|
555 734 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
556 735 | ::http_1x::response::Builder::new()
|
557 736 | .header(
|
558 737 | "X-Amzn-Errortype",
|
559 738 | "aws.protocoltests.json10#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
|
560 739 | )
|
561 740 | .status(500)
|
562 741 | .body(::aws_smithy_types::body::SdkBody::from(vec![]))
|
563 742 | .unwrap(),
|
564 743 | )
|
565 744 | .unwrap();
|
566 745 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
567 746 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
568 747 |
|
569 748 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
570 749 | let config = op.config().expect("the operation has config");
|
571 750 | let de = config
|
572 751 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
573 752 | .expect("the config must have a deserializer");
|
574 753 |
|
575 754 | // Build a config bag with the protocol for schema-based deserialization
|
576 755 | #[allow(unused_mut)]
|
577 756 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
757 + | {
|
758 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
759 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
760 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
761 + | ));
|
762 + | test_cfg.push_shared_layer(layer.freeze());
|
763 + | }
|
578 764 |
|
579 765 | let parsed = de.deserialize_streaming(&mut http_response);
|
580 766 | let parsed = parsed.unwrap_or_else(|| {
|
581 767 | let http_response = http_response.map(|body| {
|
582 768 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
583 769 | body.bytes().unwrap(),
|
584 770 | ::aws_smithy_protocol_test::MediaType::from("unknown"),
|
585 771 | )))
|
586 772 | });
|
587 773 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
588 774 | });
|
589 775 | let parsed = parsed.expect_err("should be error response");
|
590 776 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
591 777 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
592 778 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
593 779 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
594 780 | } else {
|
595 781 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
596 782 | }
|
597 783 | }
|
598 784 |
|
599 785 | /// This example uses the 'code' property in the output rather than X-Amzn-Errortype. Some services do this though it's preferable to send the X-Amzn-Errortype. Client implementations must first check for the X-Amzn-Errortype and then check for a top-level 'code' property.
|
600 786 | ///
|
601 787 | /// For example service see Amazon S3 Glacier.
|
602 788 | /// Test ID: AwsJson10FooErrorUsingCode
|
603 789 | #[::tokio::test]
|
604 790 | #[::tracing_test::traced_test]
|
605 791 | async fn aws_json10_foo_error_using_code_response() {
|
606 792 | let expected_output = crate::types::error::FooError::builder().build();
|
607 793 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
608 794 | ::http_1x::response::Builder::new()
|
609 795 | .header("Content-Type", "application/x-amz-json-1.0")
|
610 796 | .status(500)
|
611 797 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"code\": \"FooError\"\n}"))
|
612 798 | .unwrap(),
|
613 799 | )
|
614 800 | .unwrap();
|
615 801 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
616 802 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
617 803 |
|
618 804 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
619 805 | let config = op.config().expect("the operation has config");
|
620 806 | let de = config
|
621 807 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
622 808 | .expect("the config must have a deserializer");
|
623 809 |
|
624 810 | // Build a config bag with the protocol for schema-based deserialization
|
625 811 | #[allow(unused_mut)]
|
626 812 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
813 + | {
|
814 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
815 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
816 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
817 + | ));
|
818 + | test_cfg.push_shared_layer(layer.freeze());
|
819 + | }
|
627 820 |
|
628 821 | let parsed = de.deserialize_streaming(&mut http_response);
|
629 822 | let parsed = parsed.unwrap_or_else(|| {
|
630 823 | let http_response = http_response.map(|body| {
|
631 824 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
632 825 | body.bytes().unwrap(),
|
633 826 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
634 827 | )))
|
635 828 | });
|
636 829 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
637 830 | });
|
638 831 | let parsed = parsed.expect_err("should be error response");
|
639 832 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
640 833 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
641 834 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
642 835 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
643 836 | } else {
|
644 837 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
645 838 | }
|
646 839 | }
|
647 840 |
|
648 841 | /// Some services serialize errors using code, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
649 842 | /// Test ID: AwsJson10FooErrorUsingCodeAndNamespace
|
650 843 | #[::tokio::test]
|
651 844 | #[::tracing_test::traced_test]
|
652 845 | async fn aws_json10_foo_error_using_code_and_namespace_response() {
|
653 846 | let expected_output = crate::types::error::FooError::builder().build();
|
654 847 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
655 848 | ::http_1x::response::Builder::new()
|
656 849 | .header("Content-Type", "application/x-amz-json-1.0")
|
657 850 | .status(500)
|
658 851 | .body(::aws_smithy_types::body::SdkBody::from(
|
659 852 | "{\n \"code\": \"aws.protocoltests.json10#FooError\"\n}",
|
660 853 | ))
|
661 854 | .unwrap(),
|
662 855 | )
|
663 856 | .unwrap();
|
664 857 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
665 858 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
666 859 |
|
667 860 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
668 861 | let config = op.config().expect("the operation has config");
|
669 862 | let de = config
|
670 863 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
671 864 | .expect("the config must have a deserializer");
|
672 865 |
|
673 866 | // Build a config bag with the protocol for schema-based deserialization
|
674 867 | #[allow(unused_mut)]
|
675 868 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
869 + | {
|
870 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
871 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
872 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
873 + | ));
|
874 + | test_cfg.push_shared_layer(layer.freeze());
|
875 + | }
|
676 876 |
|
677 877 | let parsed = de.deserialize_streaming(&mut http_response);
|
678 878 | let parsed = parsed.unwrap_or_else(|| {
|
679 879 | let http_response = http_response.map(|body| {
|
680 880 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
681 881 | body.bytes().unwrap(),
|
682 882 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
683 883 | )))
|
684 884 | });
|
685 885 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
686 886 | });
|
687 887 | let parsed = parsed.expect_err("should be error response");
|
688 888 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
689 889 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
690 890 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
691 891 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
692 892 | } else {
|
693 893 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
694 894 | }
|
695 895 | }
|
696 896 |
|
697 897 | /// Some services serialize errors using code, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
|
698 898 | /// Test ID: AwsJson10FooErrorUsingCodeUriAndNamespace
|
699 899 | #[::tokio::test]
|
700 900 | #[::tracing_test::traced_test]
|
701 901 | async fn aws_json10_foo_error_using_code_uri_and_namespace_response() {
|
702 902 | let expected_output = crate::types::error::FooError::builder().build();
|
703 903 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
704 904 | ::http_1x::response::Builder::new()
|
705 905 | .header("Content-Type", "application/x-amz-json-1.0")
|
706 906 | .status(500)
|
707 907 | .body(::aws_smithy_types::body::SdkBody::from(
|
708 908 | "{\n \"code\": \"aws.protocoltests.json10#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
709 909 | ))
|
710 910 | .unwrap(),
|
711 911 | )
|
712 912 | .unwrap();
|
713 913 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
714 914 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
715 915 |
|
716 916 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
717 917 | let config = op.config().expect("the operation has config");
|
718 918 | let de = config
|
719 919 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
720 920 | .expect("the config must have a deserializer");
|
721 921 |
|
722 922 | // Build a config bag with the protocol for schema-based deserialization
|
723 923 | #[allow(unused_mut)]
|
724 924 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
925 + | {
|
926 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
927 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
928 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
929 + | ));
|
930 + | test_cfg.push_shared_layer(layer.freeze());
|
931 + | }
|
725 932 |
|
726 933 | let parsed = de.deserialize_streaming(&mut http_response);
|
727 934 | let parsed = parsed.unwrap_or_else(|| {
|
728 935 | let http_response = http_response.map(|body| {
|
729 936 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
730 937 | body.bytes().unwrap(),
|
731 938 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
732 939 | )))
|
733 940 | });
|
734 941 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
735 942 | });
|
736 943 | let parsed = parsed.expect_err("should be error response");
|
737 944 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
738 945 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
739 946 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
740 947 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
741 948 | } else {
|
742 949 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
743 950 | }
|
744 951 | }
|
745 952 |
|
746 953 | /// Some services serialize errors using __type.
|
747 954 | /// Test ID: AwsJson10FooErrorWithDunderType
|
748 955 | #[::tokio::test]
|
749 956 | #[::tracing_test::traced_test]
|
750 957 | async fn aws_json10_foo_error_with_dunder_type_response() {
|
751 958 | let expected_output = crate::types::error::FooError::builder().build();
|
752 959 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
753 960 | ::http_1x::response::Builder::new()
|
754 961 | .header("Content-Type", "application/x-amz-json-1.0")
|
755 962 | .status(500)
|
756 963 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"FooError\"\n}"))
|
757 964 | .unwrap(),
|
758 965 | )
|
759 966 | .unwrap();
|
760 967 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
761 968 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
762 969 |
|
763 970 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
764 971 | let config = op.config().expect("the operation has config");
|
765 972 | let de = config
|
766 973 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
767 974 | .expect("the config must have a deserializer");
|
768 975 |
|
769 976 | // Build a config bag with the protocol for schema-based deserialization
|
770 977 | #[allow(unused_mut)]
|
771 978 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
979 + | {
|
980 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
981 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
982 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
983 + | ));
|
984 + | test_cfg.push_shared_layer(layer.freeze());
|
985 + | }
|
772 986 |
|
773 987 | let parsed = de.deserialize_streaming(&mut http_response);
|
774 988 | let parsed = parsed.unwrap_or_else(|| {
|
775 989 | let http_response = http_response.map(|body| {
|
776 990 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
777 991 | body.bytes().unwrap(),
|
778 992 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
779 993 | )))
|
780 994 | });
|
781 995 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
782 996 | });
|
783 997 | let parsed = parsed.expect_err("should be error response");
|
784 998 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
785 999 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
786 1000 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
787 1001 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
788 1002 | } else {
|
789 1003 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
790 1004 | }
|
791 1005 | }
|
792 1006 |
|
793 1007 | /// Some services serialize errors using __type, and it might contain a namespace. Clients should just take the last part of the string after '#'.
|
794 1008 | /// Test ID: AwsJson10FooErrorWithDunderTypeAndNamespace
|
795 1009 | #[::tokio::test]
|
796 1010 | #[::tracing_test::traced_test]
|
797 1011 | async fn aws_json10_foo_error_with_dunder_type_and_namespace_response() {
|
798 1012 | let expected_output = crate::types::error::FooError::builder().build();
|
799 1013 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
800 1014 | ::http_1x::response::Builder::new()
|
801 1015 | .header("Content-Type", "application/x-amz-json-1.0")
|
802 1016 | .status(500)
|
803 1017 | .body(::aws_smithy_types::body::SdkBody::from(
|
804 1018 | "{\n \"__type\": \"aws.protocoltests.json10#FooError\"\n}",
|
805 1019 | ))
|
806 1020 | .unwrap(),
|
807 1021 | )
|
808 1022 | .unwrap();
|
809 1023 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
810 1024 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
811 1025 |
|
812 1026 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
813 1027 | let config = op.config().expect("the operation has config");
|
814 1028 | let de = config
|
815 1029 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
816 1030 | .expect("the config must have a deserializer");
|
817 1031 |
|
818 1032 | // Build a config bag with the protocol for schema-based deserialization
|
819 1033 | #[allow(unused_mut)]
|
820 1034 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1035 + | {
|
1036 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1037 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1038 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
1039 + | ));
|
1040 + | test_cfg.push_shared_layer(layer.freeze());
|
1041 + | }
|
821 1042 |
|
822 1043 | let parsed = de.deserialize_streaming(&mut http_response);
|
823 1044 | let parsed = parsed.unwrap_or_else(|| {
|
824 1045 | let http_response = http_response.map(|body| {
|
825 1046 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
826 1047 | body.bytes().unwrap(),
|
827 1048 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
828 1049 | )))
|
829 1050 | });
|
830 1051 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
831 1052 | });
|
832 1053 | let parsed = parsed.expect_err("should be error response");
|
833 1054 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
834 1055 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
835 1056 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
836 1057 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
837 1058 | } else {
|
838 1059 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
839 1060 | }
|
840 1061 | }
|
841 1062 |
|
842 1063 | /// Because only the part after '#' is considered, an unrecognized namespace should not make a difference.
|
843 1064 | /// Test ID: AwsJson10FooErrorWithDunderTypeAndDifferentNamespace
|
844 1065 | #[::tokio::test]
|
845 1066 | #[::tracing_test::traced_test]
|
846 1067 | async fn aws_json10_foo_error_with_dunder_type_and_different_namespace_response() {
|
847 1068 | let expected_output = crate::types::error::FooError::builder().build();
|
848 1069 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
849 1070 | ::http_1x::response::Builder::new()
|
850 1071 | .header("Content-Type", "application/x-amz-json-1.0")
|
851 1072 | .status(500)
|
852 1073 | .body(::aws_smithy_types::body::SdkBody::from(
|
853 1074 | "{\n \"__type\": \"aws.different.namespace#FooError\"\n}",
|
854 1075 | ))
|
855 1076 | .unwrap(),
|
856 1077 | )
|
857 1078 | .unwrap();
|
858 1079 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
859 1080 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
860 1081 |
|
861 1082 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
862 1083 | let config = op.config().expect("the operation has config");
|
863 1084 | let de = config
|
864 1085 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
865 1086 | .expect("the config must have a deserializer");
|
866 1087 |
|
867 1088 | // Build a config bag with the protocol for schema-based deserialization
|
868 1089 | #[allow(unused_mut)]
|
869 1090 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1091 + | {
|
1092 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1093 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1094 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
1095 + | ));
|
1096 + | test_cfg.push_shared_layer(layer.freeze());
|
1097 + | }
|
870 1098 |
|
871 1099 | let parsed = de.deserialize_streaming(&mut http_response);
|
872 1100 | let parsed = parsed.unwrap_or_else(|| {
|
873 1101 | let http_response = http_response.map(|body| {
|
874 1102 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
875 1103 | body.bytes().unwrap(),
|
876 1104 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
877 1105 | )))
|
878 1106 | });
|
879 1107 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
880 1108 | });
|
881 1109 | let parsed = parsed.expect_err("should be error response");
|
882 1110 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
883 1111 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
884 1112 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
885 1113 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
886 1114 | } else {
|
887 1115 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
888 1116 | }
|
889 1117 | }
|
890 1118 |
|
891 1119 | /// Some services serialize errors using __type, and it might contain a namespace. It also might contain a URI. Clients should just take the last part of the string after '#' and before ":". This is a pathalogical case that might not occur in any deployed AWS service.
|
892 1120 | /// Test ID: AwsJson10FooErrorWithDunderTypeUriAndNamespace
|
893 1121 | #[::tokio::test]
|
894 1122 | #[::tracing_test::traced_test]
|
895 1123 | async fn aws_json10_foo_error_with_dunder_type_uri_and_namespace_response() {
|
896 1124 | let expected_output = crate::types::error::FooError::builder().build();
|
897 1125 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(
|
898 1126 | ::http_1x::response::Builder::new()
|
899 1127 | .header("Content-Type", "application/x-amz-json-1.0")
|
900 1128 | .status(500)
|
901 1129 | .body(::aws_smithy_types::body::SdkBody::from(
|
902 1130 | "{\n \"__type\": \"aws.protocoltests.json10#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/\"\n}",
|
903 1131 | ))
|
904 1132 | .unwrap(),
|
905 1133 | )
|
906 1134 | .unwrap();
|
907 1135 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
908 1136 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
909 1137 |
|
910 1138 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
911 1139 | let config = op.config().expect("the operation has config");
|
912 1140 | let de = config
|
913 1141 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
914 1142 | .expect("the config must have a deserializer");
|
915 1143 |
|
916 1144 | // Build a config bag with the protocol for schema-based deserialization
|
917 1145 | #[allow(unused_mut)]
|
918 1146 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1147 + | {
|
1148 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1149 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1150 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
1151 + | ));
|
1152 + | test_cfg.push_shared_layer(layer.freeze());
|
1153 + | }
|
919 1154 |
|
920 1155 | let parsed = de.deserialize_streaming(&mut http_response);
|
921 1156 | let parsed = parsed.unwrap_or_else(|| {
|
922 1157 | let http_response = http_response.map(|body| {
|
923 1158 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
924 1159 | body.bytes().unwrap(),
|
925 1160 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
926 1161 | )))
|
927 1162 | });
|
928 1163 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|
929 1164 | });
|
930 1165 | let parsed = parsed.expect_err("should be error response");
|
931 1166 | let parsed: &crate::operation::greeting_with_errors::GreetingWithErrorsError =
|
932 1167 | parsed.as_operation_error().expect("operation error").downcast_ref().unwrap();
|
933 1168 | if let crate::operation::greeting_with_errors::GreetingWithErrorsError::FooError(parsed) = parsed {
|
934 1169 | ::pretty_assertions::assert_eq!(parsed.message, expected_output.message, "Unexpected value for `message`");
|
935 1170 | } else {
|
936 1171 | panic!("wrong variant: Got: {:?}. Expected: {:?}", parsed, expected_output);
|
937 1172 | }
|
938 1173 | }
|
939 1174 |
|
940 1175 | /// Some services serialize errors using __type, and if the response includes additional shapes that belong to a different namespace there'll be a nested __type property that must not be considered when determining which error to be surfaced.
|
941 1176 | ///
|
942 1177 | /// For an example service see Amazon DynamoDB.
|
943 1178 | /// Test ID: AwsJson10FooErrorWithNestedTypeProperty
|
944 1179 | #[::tokio::test]
|
945 1180 | #[::tracing_test::traced_test]
|
946 1181 | async fn aws_json10_foo_error_with_nested_type_property_response() {
|
947 1182 | let expected_output = crate::types::error::FooError::builder().build();
|
948 1183 | let mut http_response = ::aws_smithy_runtime_api::http::Response::try_from(::http_1x::response::Builder::new()
|
949 1184 | .header("Content-Type", "application/x-amz-json-1.0")
|
950 1185 | .status(500)
|
951 1186 | .body(::aws_smithy_types::body::SdkBody::from("{\n \"__type\": \"aws.protocoltests.json10#FooError\",\n \"ErrorDetails\": [\n {\n \"__type\": \"com.amazon.internal#ErrorDetails\",\n \"reason\": \"Some reason\"\n }\n ]\n}"))
|
952 1187 | .unwrap()
|
953 1188 | ).unwrap();
|
954 1189 | use ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
|
955 1190 | use ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse;
|
956 1191 |
|
957 1192 | let op = crate::operation::greeting_with_errors::GreetingWithErrors::new();
|
958 1193 | let config = op.config().expect("the operation has config");
|
959 1194 | let de = config
|
960 1195 | .load::<::aws_smithy_runtime_api::client::ser_de::SharedResponseDeserializer>()
|
961 1196 | .expect("the config must have a deserializer");
|
962 1197 |
|
963 1198 | // Build a config bag with the protocol for schema-based deserialization
|
964 1199 | #[allow(unused_mut)]
|
965 1200 | let mut test_cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
|
1201 + | {
|
1202 + | let mut layer = ::aws_smithy_types::config_bag::Layer::new("test_protocol");
|
1203 + | layer.store_put(::aws_smithy_schema::protocol::SharedClientProtocol::new(
|
1204 + | ::aws_smithy_json::protocol::aws_json_rpc::AwsJsonRpcProtocol::aws_json_1_0().with_target_prefix("JsonRpc10"),
|
1205 + | ));
|
1206 + | test_cfg.push_shared_layer(layer.freeze());
|
1207 + | }
|
966 1208 |
|
967 1209 | let parsed = de.deserialize_streaming(&mut http_response);
|
968 1210 | let parsed = parsed.unwrap_or_else(|| {
|
969 1211 | let http_response = http_response.map(|body| {
|
970 1212 | ::aws_smithy_types::body::SdkBody::from(::bytes::Bytes::copy_from_slice(&::aws_smithy_protocol_test::decode_body_data(
|
971 1213 | body.bytes().unwrap(),
|
972 1214 | ::aws_smithy_protocol_test::MediaType::from("application/json"),
|
973 1215 | )))
|
974 1216 | });
|
975 1217 | de.deserialize_nonstreaming_with_config(&http_response, &test_cfg)
|