Alamofire的一个例子是:
val paramGrid = new ParamGridBuilder()
.addGrid(hashingTF.numFeatures, Array(10, 100, 1000))
.addGrid(naiveBayes.lambda, Array(0.1, 0.01))
.build()
如何处理“网络中断”,“404”,“未找到服务器”等错误,为用户提供无法解决其原因的信息?
答案 0 :(得分:2)
您可以获取http状态代码并将其处理为:
Alamofire.request(.GET, USERS_URL, headers: headers, encoding: .JSON)
.responseJSON { response in
debugPrint(response)
switch response.result {
case .Success(let data):
if response.response!.statusCode == 200 {
//do things
}else if response.response!.statusCode == 401 {
//do things
}
case .Failure(let error):
print("Request failed with error: \(error)")
}
}