
commonMain.aws.sdk.kotlin.services.cloudsearch.transform.UpdateServiceAccessPoliciesOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.cloudsearch.transform
import aws.sdk.kotlin.services.cloudsearch.model.AccessPoliciesStatus
import aws.sdk.kotlin.services.cloudsearch.model.CloudSearchException
import aws.sdk.kotlin.services.cloudsearch.model.UpdateServiceAccessPoliciesResponse
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.awsprotocol.xml.parseRestXmlErrorResponse
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserialize
import aws.smithy.kotlin.runtime.http.readAll
import aws.smithy.kotlin.runtime.http.response.HttpResponse
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.DeserializationException
import aws.smithy.kotlin.runtime.serde.SdkFieldDescriptor
import aws.smithy.kotlin.runtime.serde.SdkObjectDescriptor
import aws.smithy.kotlin.runtime.serde.SerialKind
import aws.smithy.kotlin.runtime.serde.asSdkSerializable
import aws.smithy.kotlin.runtime.serde.deserializeList
import aws.smithy.kotlin.runtime.serde.deserializeMap
import aws.smithy.kotlin.runtime.serde.deserializeStruct
import aws.smithy.kotlin.runtime.serde.field
import aws.smithy.kotlin.runtime.serde.serializeList
import aws.smithy.kotlin.runtime.serde.serializeMap
import aws.smithy.kotlin.runtime.serde.serializeStruct
import aws.smithy.kotlin.runtime.serde.xml.XmlDeserializer
import aws.smithy.kotlin.runtime.serde.xml.XmlNamespace
import aws.smithy.kotlin.runtime.serde.xml.XmlSerialName
internal class UpdateServiceAccessPoliciesOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): UpdateServiceAccessPoliciesResponse {
if (!response.status.isSuccess()) {
throwUpdateServiceAccessPoliciesError(context, response)
}
val builder = UpdateServiceAccessPoliciesResponse.Builder()
val payload = response.body.readAll()
if (payload != null) {
deserializeUpdateServiceAccessPoliciesOperationBody(builder, payload)
}
return builder.build()
}
}
private suspend fun throwUpdateServiceAccessPoliciesError(context: ExecutionContext, response: HttpResponse): kotlin.Nothing {
val payload = response.body.readAll()
val wrappedResponse = response.withPayload(payload)
val errorDetails = try {
checkNotNull(payload){ "unable to parse error from empty response" }
parseRestXmlErrorResponse(payload)
} catch (ex: Exception) {
throw CloudSearchException("Failed to parse response as 'awsQuery' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"BaseException" -> BaseExceptionDeserializer().deserialize(context, wrappedResponse)
"InternalException" -> InternalExceptionDeserializer().deserialize(context, wrappedResponse)
"InvalidType" -> InvalidTypeExceptionDeserializer().deserialize(context, wrappedResponse)
"LimitExceeded" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedResponse)
"ResourceNotFound" -> ResourceNotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"ValidationException" -> ValidationExceptionDeserializer().deserialize(context, wrappedResponse)
else -> CloudSearchException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
private fun deserializeUpdateServiceAccessPoliciesOperationBody(builder: UpdateServiceAccessPoliciesResponse.Builder, payload: ByteArray) {
val deserializer = XmlDeserializer(payload)
// begin unwrap response wrapper
val resultDescriptor = SdkFieldDescriptor(SerialKind.Struct, XmlSerialName("UpdateServiceAccessPoliciesResult"))
val wrapperDescriptor = SdkObjectDescriptor.build {
trait(XmlSerialName("UpdateServiceAccessPoliciesResponse"))
field(resultDescriptor)
}
val wrapper = deserializer.deserializeStruct(wrapperDescriptor)
if (wrapper.findNextFieldIndex() != resultDescriptor.index) {
throw DeserializationException("failed to unwrap UpdateServiceAccessPolicies response")
}
// end unwrap response wrapper
val ACCESSPOLICIES_DESCRIPTOR = SdkFieldDescriptor(SerialKind.Struct, XmlSerialName("AccessPolicies"))
val OBJ_DESCRIPTOR = SdkObjectDescriptor.build {
trait(XmlNamespace("http://cloudsearch.amazonaws.com/doc/2013-01-01/"))
trait(XmlSerialName("UpdateServiceAccessPoliciesResult"))
field(ACCESSPOLICIES_DESCRIPTOR)
}
deserializer.deserializeStruct(OBJ_DESCRIPTOR) {
loop@while (true) {
when (findNextFieldIndex()) {
ACCESSPOLICIES_DESCRIPTOR.index -> builder.accessPolicies = deserializeAccessPoliciesStatusDocument(deserializer)
null -> break@loop
else -> skipValue()
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy