Skip to content

Commit

Permalink
Don't throw errors on failure to decode additional fields of error (#465
Browse files Browse the repository at this point in the history
)
  • Loading branch information
adam-fowler authored Oct 2, 2021
1 parent 0957202 commit 1f5878c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions Sources/SotoCore/Message/AWSResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ public struct AWSResponse {
var additionalFields: [String: String] = [:]
for key in container.allKeys {
guard key.stringValue != "Code", key.stringValue != "Message" else { continue }
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
do {
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
} catch {}
}
self.additionalFields = additionalFields
}
Expand All @@ -292,7 +294,9 @@ public struct AWSResponse {
var additionalFields: [String: String] = [:]
for key in container.allKeys {
guard key.stringValue != "__type", key.stringValue != "message", key.stringValue != "Message" else { continue }
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
do {
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
} catch {}
}
self.additionalFields = additionalFields
}
Expand All @@ -313,7 +317,9 @@ public struct AWSResponse {
var additionalFields: [String: String] = [:]
for key in container.allKeys {
guard key.stringValue != "code", key.stringValue != "message", key.stringValue != "Message" else { continue }
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
do {
additionalFields[key.stringValue] = try container.decodeIfPresent(String.self, forKey: key)
} catch {}
}
self.additionalFields = additionalFields
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SotoCoreTests/AWSResponseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class AWSResponseTests: XCTestCase {
let response = AWSHTTPResponseImpl(
status: .notFound,
headers: HTTPHeaders(),
bodyData: #"{"__type":"ResourceNotFoundException", "Message": "Donald Where's Your Troosers?", "fault": "client"}"#.data(using: .utf8)!
bodyData: #"{"__type":"ResourceNotFoundException", "Message": "Donald Where's Your Troosers?", "fault": "client","CancellationReasons":1}"#.data(using: .utf8)!
)
let service = createServiceConfig(serviceProtocol: .json(version: "1.1"), errorType: ServiceErrorType.self)

Expand Down

0 comments on commit 1f5878c

Please sign in to comment.