All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.aws.sdk.kotlin.services.route53.serde.TestDNSAnswerOperationDeserializer.kt Maven / Gradle / Ivy

The newest version!
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!

package aws.sdk.kotlin.services.route53.serde

import aws.sdk.kotlin.services.route53.model.Route53Exception
import aws.sdk.kotlin.services.route53.model.RrType
import aws.sdk.kotlin.services.route53.model.TestDnsAnswerResponse
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
import aws.smithy.kotlin.runtime.awsprotocol.xml.parseRestXmlErrorResponseNoSuspend
import aws.smithy.kotlin.runtime.http.HttpCall
import aws.smithy.kotlin.runtime.http.isSuccess
import aws.smithy.kotlin.runtime.http.operation.HttpDeserializer
import aws.smithy.kotlin.runtime.operation.ExecutionContext
import aws.smithy.kotlin.runtime.serde.getOrDeserializeErr
import aws.smithy.kotlin.runtime.serde.parse
import aws.smithy.kotlin.runtime.serde.xml.tryData
import aws.smithy.kotlin.runtime.serde.xml.xmlTagReader


internal class TestDNSAnswerOperationDeserializer: HttpDeserializer.NonStreaming {

    override fun deserialize(context: ExecutionContext, call: HttpCall, payload: ByteArray?): TestDnsAnswerResponse {
        val response = call.response
        if (!response.status.isSuccess()) {
            throwTestDnsAnswerError(context, call, payload)
        }
        val builder = TestDnsAnswerResponse.Builder()

        if (payload != null) {
            deserializeTestDNSAnswerOperationBody(builder, payload)
        }
        builder.correctErrors()
        return builder.build()
    }
}

private fun throwTestDnsAnswerError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
    val wrappedResponse = call.response.withPayload(payload)
    val wrappedCall = call.copy(response = wrappedResponse)

    val errorDetails = try {
        checkNotNull(payload){ "unable to parse error from empty response" }
        parseRestXmlErrorResponseNoSuspend(payload)
    } catch (ex: Exception) {
        throw Route53Exception("Failed to parse response as 'restXml' error", ex).also {
            setAseErrorMetadata(it, wrappedCall.response, null)
        }
    }

    val ex = when(errorDetails.code) {
        "InvalidInput" -> InvalidInputDeserializer().deserialize(context, wrappedCall, payload)
        "NoSuchHostedZone" -> NoSuchHostedZoneDeserializer().deserialize(context, wrappedCall, payload)
        else -> Route53Exception(errorDetails.message)
    }

    setAseErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

private fun deserializeTestDNSAnswerOperationBody(builder: TestDnsAnswerResponse.Builder, payload: ByteArray) {
    val root = xmlTagReader(payload)

    loop@while (true) {
        val curr = root.nextTag() ?: break@loop
        when (curr.tagName) {
            // Nameserver com.amazonaws.route53#TestDNSAnswerResponse$Nameserver
            "Nameserver" -> builder.nameserver = curr.tryData()
                .getOrDeserializeErr { "expected (string: `com.amazonaws.route53#Nameserver`)" }
            // Protocol com.amazonaws.route53#TestDNSAnswerResponse$Protocol
            "Protocol" -> builder.protocol = curr.tryData()
                .getOrDeserializeErr { "expected (string: `com.amazonaws.route53#TransportProtocol`)" }
            // RecordData com.amazonaws.route53#TestDNSAnswerResponse$RecordData
            "RecordData" -> builder.recordData = deserializeRecordDataShape(curr)
            // RecordName com.amazonaws.route53#TestDNSAnswerResponse$RecordName
            "RecordName" -> builder.recordName = curr.tryData()
                .getOrDeserializeErr { "expected (string: `com.amazonaws.route53#DNSName`)" }
            // RecordType com.amazonaws.route53#TestDNSAnswerResponse$RecordType
            "RecordType" -> builder.recordType = curr.tryData()
                .parse { RrType.fromValue(it) }
                .getOrDeserializeErr { "expected (enum: `com.amazonaws.route53#RRType`)" }
            // ResponseCode com.amazonaws.route53#TestDNSAnswerResponse$ResponseCode
            "ResponseCode" -> builder.responseCode = curr.tryData()
                .getOrDeserializeErr { "expected (string: `com.amazonaws.route53#DNSRCode`)" }
            else -> {}
        }
        curr.drop()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy