commonMain.aws.sdk.kotlin.services.kms.transform.PutKeyPolicyOperationDeserializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kms Show documentation
Show all versions of kms Show documentation
The AWS Kotlin client for KMS
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.kms.transform
import aws.sdk.kotlin.services.kms.model.KmsException
import aws.sdk.kotlin.services.kms.model.PutKeyPolicyResponse
import aws.smithy.kotlin.runtime.awsprotocol.json.RestJsonErrorDeserializer
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
import aws.smithy.kotlin.runtime.awsprotocol.withPayload
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
internal class PutKeyPolicyOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): PutKeyPolicyResponse {
if (!response.status.isSuccess()) {
throwPutKeyPolicyError(context, response)
}
val builder = PutKeyPolicyResponse.Builder()
return builder.build()
}
}
private suspend fun throwPutKeyPolicyError(context: ExecutionContext, response: HttpResponse): kotlin.Nothing {
val payload = response.body.readAll()
val wrappedResponse = response.withPayload(payload)
val errorDetails = try {
RestJsonErrorDeserializer.deserialize(response.headers, payload)
} catch (ex: Exception) {
throw KmsException("Failed to parse response as 'awsJson1_1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"DependencyTimeoutException" -> DependencyTimeoutExceptionDeserializer().deserialize(context, wrappedResponse)
"InvalidArnException" -> InvalidArnExceptionDeserializer().deserialize(context, wrappedResponse)
"KMSInternalException" -> KmsInternalExceptionDeserializer().deserialize(context, wrappedResponse)
"KMSInvalidStateException" -> KmsInvalidStateExceptionDeserializer().deserialize(context, wrappedResponse)
"LimitExceededException" -> LimitExceededExceptionDeserializer().deserialize(context, wrappedResponse)
"MalformedPolicyDocumentException" -> MalformedPolicyDocumentExceptionDeserializer().deserialize(context, wrappedResponse)
"NotFoundException" -> NotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"UnsupportedOperationException" -> UnsupportedOperationExceptionDeserializer().deserialize(context, wrappedResponse)
else -> KmsException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy