我在我的应用程序中使用 Uber Api。尝试预订行程时出现问题。我收到 httpStatus 400 错误。根据他们的文档,这可能是由于多种因素造成的。

我怎么能通过状态代码(总是“400”)知道给定类型的哪个描述导致它?
我现在的代码:
if let httpstatuscode = response as? NSHTTPURLResponse
{
if (error != nil)
{
print("Error : \(error?.localizedDescription)")
}
else if httpstatuscode.statusCode != 202 && httpstatuscode.statusCode != 409
{
print("Status Code\(httpstatuscode.statusCode)")
dispatch_async(dispatch_get_main_queue(), { () -> Void in
CommonViewController.alertViewUI("Alert", message: "Internal Server Error!")
})
}
else if httpstatuscode.statusCode == 409
{
// self.getUberRideLive()
print("Status Code\(httpstatuscode.statusCode)")
CommonViewController.alertViewUI("Alert", message: "You are already on a ride!")
}
Run Code Online (Sandbox Code Playgroud)
您可以使用该localizedString(forStatusCode:) 方法从HTTPURLResponse 类
如果您想获取 HTTP 错误的描述,这是有效的,如果您想要来自 UBER 错误的描述,您应该查看来自 UBER 操作的 JSON 响应。
然后,你的代码应该看起来像......
let message: String = HTTPURLResponse.localizedString(forStatusCode: httpstatuscode.statusCode)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1497 次 |
| 最近记录: |