-
Notifications
You must be signed in to change notification settings - Fork 80
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!: Closure-based reader-writer serde for JSON, FormURL #1439
Changes from 19 commits
de363f2
214e5f7
e94c729
c192aaf
9c738c3
2575369
3316fab
b434813
2e148ce
e312db9
62a2cd2
6da7dca
91d8a76
a7d0436
078cbfe
045fc32
67df793
a4a06cc
3f75173
9667f31
05f3110
2a2382f
f59f1f4
a48de94
075ae45
37c4bd3
00e5feb
0c8fbcc
bd98fab
8f39040
785af50
2b4b3a5
97d840d
7a379c7
3c39ef3
32ee5c9
2268700
82d1da2
6de7ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,30 +58,31 @@ extension UnknownAWSHTTPServiceError { | |
/// - requestID2: The request ID2 associated with this error (ID2 used on S3 only.) Defaults to `nil`. | ||
/// - typeName: The non-namespaced name of the error type for this error, or `nil`. | ||
/// - Returns: An error that represents the response. | ||
public static func makeError( | ||
httpResponse: HttpResponse, | ||
message: String?, | ||
requestID: String?, | ||
requestID2: String? = nil, | ||
typeName: String? | ||
) async throws -> Error { | ||
public static func makeError<Base: BaseError>( | ||
baseError: Base | ||
) throws -> Error { | ||
let candidates: [UnknownAWSHTTPErrorCandidate.Type] = [ | ||
InvalidAccessKeyId.self | ||
] | ||
if let Candidate = candidates.first(where: { $0.errorCode == typeName }) { | ||
if let Candidate = candidates.first(where: { $0.errorCode == baseError.code }) { | ||
return Candidate.init( | ||
httpResponse: httpResponse, | ||
message: message, | ||
requestID: requestID, | ||
requestID2: requestID2 | ||
httpResponse: baseError.httpResponse, | ||
message: baseError.message, | ||
requestID: baseError.requestID, | ||
requestID2: baseError.requestID2 | ||
) | ||
} | ||
return UnknownAWSHTTPServiceError( | ||
httpResponse: httpResponse, | ||
message: message, | ||
requestID: requestID, | ||
requestID2: requestID2, | ||
typeName: typeName | ||
httpResponse: baseError.httpResponse, | ||
message: baseError.message, | ||
requestID: baseError.requestID, | ||
requestID2: baseError.requestID2, | ||
typeName: baseError.code | ||
) | ||
} | ||
} | ||
|
||
extension ClientRuntime.BaseError { | ||
|
||
var requestID2: String? { nil } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extends BaseError with a default implementation for requestID2. XML/S3 will provide a concrete implementation for this field. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import protocol ClientRuntime.BaseError | ||
import enum ClientRuntime.BaseErrorDecodeError | ||
import class ClientRuntime.HttpResponse | ||
import class SmithyJSON.Reader | ||
|
||
public struct AWSJSONError: BaseError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "base error" for use with AWS JSON 1.0 / 1.1. Provides values for the common error fields. |
||
public let code: String | ||
public let message: String? | ||
public let requestID: String? | ||
public var errorBodyReader: Reader { responseReader } | ||
|
||
public let httpResponse: HttpResponse | ||
private let responseReader: Reader | ||
|
||
public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws { | ||
let code: String? = try httpResponse.headers.value(for: "X-Amzn-Errortype") | ||
?? responseReader["code"].readIfPresent() | ||
?? responseReader["__type"].readIfPresent() | ||
let message: String? = try responseReader["Message"].readIfPresent() | ||
let requestID: String? = try responseReader["RequestId"].readIfPresent() | ||
guard let code else { throw BaseErrorDecodeError.missingRequiredData } | ||
self.code = sanitizeErrorType(code) | ||
self.message = message | ||
self.requestID = requestID | ||
self.httpResponse = httpResponse | ||
self.responseReader = responseReader | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import protocol ClientRuntime.BaseError | ||
import enum ClientRuntime.BaseErrorDecodeError | ||
import class ClientRuntime.HttpResponse | ||
import class SmithyXML.Reader | ||
|
||
public struct AWSQueryError: BaseError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "base error" for use with AWS Query. Provides values for the common error fields. |
||
public let code: String | ||
public let message: String? | ||
public let requestID: String? | ||
public let httpResponse: HttpResponse | ||
public let responseReader: Reader | ||
public let errorBodyReader: Reader | ||
|
||
public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws { | ||
self.errorBodyReader = noErrorWrapping ? responseReader : responseReader["Error"] | ||
let code: String? = try errorBodyReader["Code"].readIfPresent() | ||
let message: String? = try errorBodyReader["Message"].readIfPresent() | ||
let requestID: String? = try responseReader["RequestId"].readIfPresent() | ||
guard let code else { throw BaseErrorDecodeError.missingRequiredData } | ||
self.code = code | ||
self.message = message | ||
self.requestID = requestID | ||
self.httpResponse = httpResponse | ||
self.responseReader = responseReader | ||
} | ||
} | ||
|
||
public enum AWSQueryDecodeError: Error { | ||
case missingRequiredData | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import protocol ClientRuntime.BaseError | ||
import enum ClientRuntime.BaseErrorDecodeError | ||
import class ClientRuntime.HttpResponse | ||
import class SmithyXML.Reader | ||
|
||
public struct EC2QueryError: BaseError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "base error" for use with EC2Query. Provides values for the common error fields. |
||
public let code: String | ||
public let message: String? | ||
public let requestID: String? | ||
public let errorBodyReader: Reader | ||
|
||
public let httpResponse: HttpResponse | ||
public let responseReader: Reader | ||
|
||
public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws { | ||
self.httpResponse = httpResponse | ||
self.responseReader = responseReader | ||
self.errorBodyReader = responseReader["Errors"]["Error"] | ||
let code: String? = try errorBodyReader["Code"].readIfPresent() | ||
guard let code else { throw BaseErrorDecodeError.missingRequiredData } | ||
let message: String? = try errorBodyReader["Message"].readIfPresent() | ||
let requestID: String? = try responseReader["RequestId"].readIfPresent() | ||
?? responseReader["RequestID"].readIfPresent() | ||
self.code = code | ||
self.message = message | ||
self.requestID = requestID | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to take a
BaseError
as its param