Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zgmingyeah opened this issue Feb 18, 2022 · 0 comments

Comments

@zgmingyeah
Copy link

zgmingyeah commented Feb 18, 2022

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
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant