Foundation icon indicating copy to clipboard operation
Foundation copied to clipboard

How to get the response.result.failure.sessionTaskFailed(error:error)[email protected], Thank you.

Open zgmingyeah opened this issue 3 years ago • 0 comments

How to get the response.result.failure.sessionTaskFailed(error:error)[email protected], Thank you.

struct LoginParam: Encodable {
    var phone: String? = ""
    var verificationCode: String? = ""
}

class AViewModel: NSObject {
    
    func requestForLogin(completionHandler : @escaping (DataResponse<LoginModel, AFError>) -> Void) {
        let loginParam:LoginParam = LoginParam(phone: "12345678901", verificationCode: "1234")
        AF.request("https://xxx", method: .post, parameters: loginParam, encoder: URLEncodedFormParameterEncoder(destination: .httpBody)).responseDecodable(of: LoginModel.self) { response in
            switch response.result {
            case .success(let value):
                debugPrint(value)
                break
            case .failure(let error):
                debugPrint(error)
                switch error {
                case .sessionTaskFailed(error: let a):
                    debugPrint(a)
                default:
                    debugPrint("default")
                }
                break
            }
        }
    }
}

zgmingyeah avatar Feb 18 '22 03:02 zgmingyeah