Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for awsQueryCompatible trait #850

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.swift.codegen.integration.httpResponse

import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.shapes.OperationShape
Expand All @@ -14,6 +15,7 @@ import software.amazon.smithy.swift.codegen.integration.HTTPProtocolCustomizable
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
import software.amazon.smithy.swift.codegen.integration.serde.struct.readerSymbol
import software.amazon.smithy.swift.codegen.model.getTrait
import software.amazon.smithy.swift.codegen.model.hasTrait
import software.amazon.smithy.swift.codegen.model.toUpperCamelCase
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyHTTPAPITypes
import software.amazon.smithy.swift.codegen.swiftmodules.SwiftSymbol
Expand Down Expand Up @@ -89,11 +91,20 @@ class HTTPResponseBindingErrorGenerator(
writer.write("let data = try await httpResponse.data()")
writer.write("let responseReader = try \$N.from(data: data)", ctx.service.readerSymbol)
val noErrorWrapping = ctx.service.getTrait<RestXmlTrait>()?.isNoErrorWrapping ?: false
writer.write(
"let baseError = try \$N(httpResponse: httpResponse, responseReader: responseReader, noErrorWrapping: \$L)",
customizations.baseErrorSymbol,
noErrorWrapping
)
if (ctx.service.hasTrait<AwsQueryCompatibleTrait>()) {
writer.write("let errorDetails = httpResponse.headers.value(for: \"x-amzn-query-error\")")
writer.write(
"let baseError = try \$N.makeQueryCompatibleAWSJsonError(httpResponse: httpResponse, responseReader: responseReader, noErrorWrapping: \$L, errorDetails: errorDetails)",
customizations.baseErrorSymbol,
noErrorWrapping
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my notes in the other PR. I'd prefer to roll this logic into the AWSJSONError constructor.

} else {
writer.write(
"let baseError = try \$N(httpResponse: httpResponse, responseReader: responseReader, noErrorWrapping: \$L)",
customizations.baseErrorSymbol,
noErrorWrapping
)
}
writer.write("if let error = baseError.customError() { return error }")
if (ctx.service.errors.isNotEmpty() || customizations.serviceErrorCustomRenderer(ctx) != null) {
writer.write("if let error = try httpServiceError(baseError: baseError) { return error }")
Expand Down
Loading