Skip to content

Commit 427f685

Browse files
committed
not optional response in success block
1 parent d753b77 commit 427f685

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

StudyplusSDK/StudyplusAPIRequest.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal struct StudyplusAPIRequest {
3535
self.accessToken = accessToken
3636
}
3737

38-
internal func post(path: String, params: [String: Any], success: @escaping (_ response: [AnyHashable: Any]?) -> Void, failure: @escaping (_ error: StudyplusError) -> Void) {
38+
internal func post(path: String, params: [String: Any], success: @escaping (_ response: [AnyHashable: Any]) -> Void, failure: @escaping (_ error: StudyplusError) -> Void) {
3939

4040
start(path: path, method: "POST", body: params, success: { (response) in
4141

@@ -57,7 +57,7 @@ internal struct StudyplusAPIRequest {
5757

5858
// MARK: - private
5959

60-
private func start(path: String, method: String, body: [String: Any], success: @escaping (_ response: [AnyHashable: Any]?) -> Void, failure: @escaping (_ statusCode: Int, _ response: [String: Any]?) -> Void) {
60+
private func start(path: String, method: String, body: [String: Any], success: @escaping (_ response: [AnyHashable: Any]) -> Void, failure: @escaping (_ statusCode: Int, _ response: [String: Any]?) -> Void) {
6161

6262
guard let url = buildUrl(path: path) else {
6363
failure(0, nil)
@@ -102,16 +102,21 @@ internal struct StudyplusAPIRequest {
102102

103103
do {
104104
let jsonObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
105-
success(jsonObject as? [String : Any])
106-
return
105+
guard let obj = jsonObject as? [String: Any] else {
106+
failure(0, nil)
107+
return
108+
}
109+
110+
success(obj)
111+
107112
} catch {
108113
#if DEBUG
109114
print("-- StudyplusAPIRequest Json Error Path: \(url.absoluteString), Method: \(method), Description: \(error.localizedDescription) --")
110115
#endif
111116
failure(httpResponse.statusCode, ["message": error.localizedDescription])
112117
}
113118
case 204:
114-
success(nil)
119+
success([:])
115120
return
116121
default:
117122
#if DEBUG

0 commit comments

Comments
 (0)