
aws.sdk.kotlin.services.pinpoint.transform.GetJourneyExecutionMetricsOperationDeserializer.kt Maven / Gradle / Ivy
// Code generated by smithy-kotlin-codegen. DO NOT EDIT!
package aws.sdk.kotlin.services.pinpoint.transform
import aws.sdk.kotlin.runtime.http.setAseErrorMetadata
import aws.sdk.kotlin.runtime.http.withPayload
import aws.sdk.kotlin.runtime.protocol.json.RestJsonErrorDeserializer
import aws.sdk.kotlin.services.pinpoint.model.GetJourneyExecutionMetricsResponse
import aws.sdk.kotlin.services.pinpoint.model.JourneyExecutionMetricsResponse
import aws.sdk.kotlin.services.pinpoint.model.PinpointException
import aws.smithy.kotlin.runtime.client.ExecutionContext
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
internal class GetJourneyExecutionMetricsOperationDeserializer: HttpDeserialize {
override suspend fun deserialize(context: ExecutionContext, response: HttpResponse): GetJourneyExecutionMetricsResponse {
if (!response.status.isSuccess()) {
throwGetJourneyExecutionMetricsError(context, response)
}
val builder = GetJourneyExecutionMetricsResponse.Builder()
val payload = response.body.readAll()
if (payload != null) {
builder.journeyExecutionMetricsResponse = deserializeJourneyExecutionMetricsResponsePayload(payload)
}
return builder.build()
}
}
private suspend fun throwGetJourneyExecutionMetricsError(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 PinpointException("Failed to parse response as 'restJson1' error", ex).also {
setAseErrorMetadata(it, wrappedResponse, null)
}
}
val ex = when(errorDetails.code) {
"BadRequestException" -> BadRequestExceptionDeserializer().deserialize(context, wrappedResponse)
"ForbiddenException" -> ForbiddenExceptionDeserializer().deserialize(context, wrappedResponse)
"InternalServerErrorException" -> InternalServerErrorExceptionDeserializer().deserialize(context, wrappedResponse)
"MethodNotAllowedException" -> MethodNotAllowedExceptionDeserializer().deserialize(context, wrappedResponse)
"NotFoundException" -> NotFoundExceptionDeserializer().deserialize(context, wrappedResponse)
"PayloadTooLargeException" -> PayloadTooLargeExceptionDeserializer().deserialize(context, wrappedResponse)
"TooManyRequestsException" -> TooManyRequestsExceptionDeserializer().deserialize(context, wrappedResponse)
else -> PinpointException(errorDetails.message)
}
setAseErrorMetadata(ex, wrappedResponse, errorDetails)
throw ex
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy