aws_sdk_securityhub/protocol_serde/
shape_delete_insight.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_delete_insight_http_error(
4    _response_status: u16,
5    _response_headers: &::aws_smithy_runtime_api::http::Headers,
6    _response_body: &[u8],
7) -> std::result::Result<crate::operation::delete_insight::DeleteInsightOutput, crate::operation::delete_insight::DeleteInsightError> {
8    #[allow(unused_mut)]
9    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
10        .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
11    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
12    let generic = generic_builder.build();
13    let error_code = match generic.code() {
14        Some(code) => code,
15        None => return Err(crate::operation::delete_insight::DeleteInsightError::unhandled(generic)),
16    };
17
18    let _error_message = generic.message().map(|msg| msg.to_owned());
19    Err(match error_code {
20        "InternalException" => crate::operation::delete_insight::DeleteInsightError::InternalException({
21            #[allow(unused_mut)]
22            let mut tmp = {
23                #[allow(unused_mut)]
24                let mut output = crate::types::error::builders::InternalExceptionBuilder::default();
25                output = crate::protocol_serde::shape_internal_exception::de_internal_exception_json_err(_response_body, output)
26                    .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
27                let output = output.meta(generic);
28                output.build()
29            };
30            if tmp.message.is_none() {
31                tmp.message = _error_message;
32            }
33            tmp
34        }),
35        "InvalidAccessException" => crate::operation::delete_insight::DeleteInsightError::InvalidAccessException({
36            #[allow(unused_mut)]
37            let mut tmp = {
38                #[allow(unused_mut)]
39                let mut output = crate::types::error::builders::InvalidAccessExceptionBuilder::default();
40                output = crate::protocol_serde::shape_invalid_access_exception::de_invalid_access_exception_json_err(_response_body, output)
41                    .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
42                let output = output.meta(generic);
43                output.build()
44            };
45            if tmp.message.is_none() {
46                tmp.message = _error_message;
47            }
48            tmp
49        }),
50        "InvalidInputException" => crate::operation::delete_insight::DeleteInsightError::InvalidInputException({
51            #[allow(unused_mut)]
52            let mut tmp = {
53                #[allow(unused_mut)]
54                let mut output = crate::types::error::builders::InvalidInputExceptionBuilder::default();
55                output = crate::protocol_serde::shape_invalid_input_exception::de_invalid_input_exception_json_err(_response_body, output)
56                    .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
57                let output = output.meta(generic);
58                output.build()
59            };
60            if tmp.message.is_none() {
61                tmp.message = _error_message;
62            }
63            tmp
64        }),
65        "LimitExceededException" => crate::operation::delete_insight::DeleteInsightError::LimitExceededException({
66            #[allow(unused_mut)]
67            let mut tmp = {
68                #[allow(unused_mut)]
69                let mut output = crate::types::error::builders::LimitExceededExceptionBuilder::default();
70                output = crate::protocol_serde::shape_limit_exceeded_exception::de_limit_exceeded_exception_json_err(_response_body, output)
71                    .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
72                let output = output.meta(generic);
73                output.build()
74            };
75            if tmp.message.is_none() {
76                tmp.message = _error_message;
77            }
78            tmp
79        }),
80        "ResourceNotFoundException" => crate::operation::delete_insight::DeleteInsightError::ResourceNotFoundException({
81            #[allow(unused_mut)]
82            let mut tmp = {
83                #[allow(unused_mut)]
84                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
85                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
86                    .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
87                let output = output.meta(generic);
88                output.build()
89            };
90            if tmp.message.is_none() {
91                tmp.message = _error_message;
92            }
93            tmp
94        }),
95        _ => crate::operation::delete_insight::DeleteInsightError::generic(generic),
96    })
97}
98
99#[allow(clippy::unnecessary_wraps)]
100pub fn de_delete_insight_http_response(
101    _response_status: u16,
102    _response_headers: &::aws_smithy_runtime_api::http::Headers,
103    _response_body: &[u8],
104) -> std::result::Result<crate::operation::delete_insight::DeleteInsightOutput, crate::operation::delete_insight::DeleteInsightError> {
105    Ok({
106        #[allow(unused_mut)]
107        let mut output = crate::operation::delete_insight::builders::DeleteInsightOutputBuilder::default();
108        output = crate::protocol_serde::shape_delete_insight::de_delete_insight(_response_body, output)
109            .map_err(crate::operation::delete_insight::DeleteInsightError::unhandled)?;
110        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
111        crate::serde_util::delete_insight_output_output_correct_errors(output).build()
112    })
113}
114
115pub(crate) fn de_delete_insight(
116    value: &[u8],
117    mut builder: crate::operation::delete_insight::builders::DeleteInsightOutputBuilder,
118) -> ::std::result::Result<
119    crate::operation::delete_insight::builders::DeleteInsightOutputBuilder,
120    ::aws_smithy_json::deserialize::error::DeserializeError,
121> {
122    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
123    let tokens = &mut tokens_owned;
124    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
125    loop {
126        match tokens.next().transpose()? {
127            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
128            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
129                "InsightArn" => {
130                    builder = builder.set_insight_arn(
131                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
132                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
133                            .transpose()?,
134                    );
135                }
136                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
137            },
138            other => {
139                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
140                    "expected object key or end object, found: {other:?}"
141                )))
142            }
143        }
144    }
145    if tokens.next().is_some() {
146        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
147            "found more JSON tokens after completing parsing",
148        ));
149    }
150    Ok(builder)
151}