Skip to content

Commit 409b12e

Browse files
committed
Update DataBoolMapper to parse content also without the data envelope
1 parent 2745814 commit 409b12e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Networking/Networking/Mapper/DataBoolMapper.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import Foundation
22

3-
/// Mapper: Bool Result Wrapped in `data` Key
3+
/// Mapper: Bool Result, Wrapped in `data` Key or not
44
///
55
struct DataBoolMapper: Mapper {
66

77
/// (Attempts) to extract the boolean flag from a given JSON Encoded response.
88
///
99
func map(response: Data) throws -> Bool {
10-
try JSONDecoder().decode(DataBool.self, from: response).data
10+
do {
11+
return try JSONDecoder().decode(DataBool.self, from: response).data
12+
} catch {
13+
return try JSONDecoder().decode(Bool.self, from: response)
14+
}
1115
}
1216
}
1317

0 commit comments

Comments
 (0)