-13 Removals
+24 Additions

requestBase: callback to promise

Created by:macabeus

1func requestBase(url: String, ...1func requestBase(url: String, ...) -> Promise<JSON> {
2 errorHandle: @escaping (JSON, Int) -> (Void),
3 success: @escaping (JSON) -> (Void)) {
4 ...2 ...
53
6 Alamofire.request(4 return Promise { fulfill, reject in
7 self.urlBase + url,5 Alamofire.request(
8 ...6 self.urlBase + url,
9 ).responseJSON(completionHandler: {7 ...
10 response in8 ).responseJSON(completionHandler: {
11 let statusCode = (response.response?.statusCode)!9 response in
12 var json: JSON?10 let statusCode = (response.response?.statusCode)!
11 var json: JSON?
1312
14 if let resultValue = response.result.value {13 if let resultValue = response.result.value {
15 json = JSON(resultValue)14 json = JSON(resultValue)
16 }15 }
1716
18 if (statusCode != 200) && (statusCode != 201) {17 if (statusCode != 200) && (statusCode != 201) {
19 errorHandle(json, statusCode)18 reject(NSError(json: json, code: statusCode))
20 return19 return
21 }20 }
2221
23 success(json)22 fulfill(json!)
24 })23 })
25}24 }
25}
Editor
Original Text
Changed Text
Recommended videos