requestBase: callback to promise

Created by:macabeus

func requestBase(url: String, ...func requestBase(url: String, ...) -> Promise<JSON> {
errorHandle: @escaping (JSON, Int) -> (Void),
success: @escaping (JSON) -> (Void)) {
... ...
Alamofire.request( return Promise { fulfill, reject in
self.urlBase + url, Alamofire.request(
... self.urlBase + url,
).responseJSON(completionHandler: { ...
response in ).responseJSON(completionHandler: {
let statusCode = (response.response?.statusCode)! response in
var json: JSON? let statusCode = (response.response?.statusCode)!
var json: JSON?
if let resultValue = response.result.value { if let resultValue = response.result.value {
json = JSON(resultValue) json = JSON(resultValue)
} }
if (statusCode != 200) && (statusCode != 201) { if (statusCode != 200) && (statusCode != 201) {
errorHandle(json, statusCode) reject(NSError(json: json, code: statusCode))
return return
} }
success(json) fulfill(json!)
}) })
} }
}
original text
changed text