@@ -35,7 +35,7 @@ internal struct StudyplusAPIRequest {
35
35
self . accessToken = accessToken
36
36
}
37
37
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 ) {
39
39
40
40
start ( path: path, method: " POST " , body: params, success: { ( response) in
41
41
@@ -57,7 +57,7 @@ internal struct StudyplusAPIRequest {
57
57
58
58
// MARK: - private
59
59
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 ) {
61
61
62
62
guard let url = buildUrl ( path: path) else {
63
63
failure ( 0 , nil )
@@ -102,16 +102,21 @@ internal struct StudyplusAPIRequest {
102
102
103
103
do {
104
104
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
+
107
112
} catch {
108
113
#if DEBUG
109
114
print ( " -- StudyplusAPIRequest Json Error Path: \( url. absoluteString) , Method: \( method) , Description: \( error. localizedDescription) -- " )
110
115
#endif
111
116
failure ( httpResponse. statusCode, [ " message " : error. localizedDescription] )
112
117
}
113
118
case 204 :
114
- success ( nil )
119
+ success ( [ : ] )
115
120
return
116
121
default :
117
122
#if DEBUG
0 commit comments