13 removals
24 additions

requestBase: callback to promise

Created by:macabeus

1.func requestBase(url: String, ...1.func requestBase(url: String, ...) -> Promise<JSON> {
2. errorHandle: @escaping (JSON, Int) -> (Void),
3. success: @escaping (JSON) -> (Void)) {
4. ...2. ...
5.3.
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?
13.12.
14. if let resultValue = response.result.value {13. if let resultValue = response.result.value {
15. json = JSON(resultValue)14. json = JSON(resultValue)
16. }15. }
17.16.
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. }
22.21.
23. success(json)22. fulfill(json!)
24. })23. })
25.}24. }
25.}
original text
changed text