requestBase: callback to promise

Created Diff never expires
7 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
25 lines
21 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
26 lines
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!)
})
})
}
}
}