aws_sdk_comprehend/protocol_serde/
shape_describe_sentiment_detection_job.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_describe_sentiment_detection_job_http_error(
4    _response_status: u16,
5    _response_headers: &::aws_smithy_runtime_api::http::Headers,
6    _response_body: &[u8],
7) -> std::result::Result<
8    crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobOutput,
9    crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError,
10> {
11    #[allow(unused_mut)]
12    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
13        .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
14    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
15    let generic = generic_builder.build();
16    let error_code = match generic.code() {
17        Some(code) => code,
18        None => return Err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled(generic)),
19    };
20
21    let _error_message = generic.message().map(|msg| msg.to_owned());
22    Err(match error_code {
23        "InternalServerException" => {
24            crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::InternalServerException({
25                #[allow(unused_mut)]
26                let mut tmp = {
27                    #[allow(unused_mut)]
28                    let mut output = crate::types::error::builders::InternalServerExceptionBuilder::default();
29                    output = crate::protocol_serde::shape_internal_server_exception::de_internal_server_exception_json_err(_response_body, output)
30                        .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
31                    let output = output.meta(generic);
32                    output.build()
33                };
34                if tmp.message.is_none() {
35                    tmp.message = _error_message;
36                }
37                tmp
38            })
39        }
40        "InvalidRequestException" => {
41            crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::InvalidRequestException({
42                #[allow(unused_mut)]
43                let mut tmp = {
44                    #[allow(unused_mut)]
45                    let mut output = crate::types::error::builders::InvalidRequestExceptionBuilder::default();
46                    output = crate::protocol_serde::shape_invalid_request_exception::de_invalid_request_exception_json_err(_response_body, output)
47                        .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
48                    let output = output.meta(generic);
49                    output.build()
50                };
51                if tmp.message.is_none() {
52                    tmp.message = _error_message;
53                }
54                tmp
55            })
56        }
57        "JobNotFoundException" => crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::JobNotFoundException({
58            #[allow(unused_mut)]
59            let mut tmp = {
60                #[allow(unused_mut)]
61                let mut output = crate::types::error::builders::JobNotFoundExceptionBuilder::default();
62                output = crate::protocol_serde::shape_job_not_found_exception::de_job_not_found_exception_json_err(_response_body, output)
63                    .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
64                let output = output.meta(generic);
65                output.build()
66            };
67            if tmp.message.is_none() {
68                tmp.message = _error_message;
69            }
70            tmp
71        }),
72        "TooManyRequestsException" => {
73            crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::TooManyRequestsException({
74                #[allow(unused_mut)]
75                let mut tmp = {
76                    #[allow(unused_mut)]
77                    let mut output = crate::types::error::builders::TooManyRequestsExceptionBuilder::default();
78                    output =
79                        crate::protocol_serde::shape_too_many_requests_exception::de_too_many_requests_exception_json_err(_response_body, output)
80                            .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
81                    let output = output.meta(generic);
82                    output.build()
83                };
84                if tmp.message.is_none() {
85                    tmp.message = _error_message;
86                }
87                tmp
88            })
89        }
90        _ => crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::generic(generic),
91    })
92}
93
94#[allow(clippy::unnecessary_wraps)]
95pub fn de_describe_sentiment_detection_job_http_response(
96    _response_status: u16,
97    _response_headers: &::aws_smithy_runtime_api::http::Headers,
98    _response_body: &[u8],
99) -> std::result::Result<
100    crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobOutput,
101    crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError,
102> {
103    Ok({
104        #[allow(unused_mut)]
105        let mut output = crate::operation::describe_sentiment_detection_job::builders::DescribeSentimentDetectionJobOutputBuilder::default();
106        output = crate::protocol_serde::shape_describe_sentiment_detection_job::de_describe_sentiment_detection_job(_response_body, output)
107            .map_err(crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobError::unhandled)?;
108        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
109        output.build()
110    })
111}
112
113pub fn ser_describe_sentiment_detection_job_input(
114    input: &crate::operation::describe_sentiment_detection_job::DescribeSentimentDetectionJobInput,
115) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
116    let mut out = String::new();
117    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
118    crate::protocol_serde::shape_describe_sentiment_detection_job_input::ser_describe_sentiment_detection_job_input_input(&mut object, input)?;
119    object.finish();
120    Ok(::aws_smithy_types::body::SdkBody::from(out))
121}
122
123pub(crate) fn de_describe_sentiment_detection_job(
124    value: &[u8],
125    mut builder: crate::operation::describe_sentiment_detection_job::builders::DescribeSentimentDetectionJobOutputBuilder,
126) -> ::std::result::Result<
127    crate::operation::describe_sentiment_detection_job::builders::DescribeSentimentDetectionJobOutputBuilder,
128    ::aws_smithy_json::deserialize::error::DeserializeError,
129> {
130    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
131    let tokens = &mut tokens_owned;
132    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
133    loop {
134        match tokens.next().transpose()? {
135            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
136            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
137                "SentimentDetectionJobProperties" => {
138                    builder = builder.set_sentiment_detection_job_properties(
139                        crate::protocol_serde::shape_sentiment_detection_job_properties::de_sentiment_detection_job_properties(tokens)?,
140                    );
141                }
142                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
143            },
144            other => {
145                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
146                    "expected object key or end object, found: {other:?}"
147                )))
148            }
149        }
150    }
151    if tokens.next().is_some() {
152        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
153            "found more JSON tokens after completing parsing",
154        ));
155    }
156    Ok(builder)
157}