Alamofire
return sessionManager.upload(multipartFormData: { multipartFormData in
multipartFormData.append(export.url, withName: "ipa")
multipartFormData.append(export.manifest.url, withName: "plist")
}, with: urlRequest, queue: self.queue, encodingCompletion: { result in
switch result {
case .success(let upload, _, _):
upload.validate().responseData(queue: self.queue) { response in
switch (response.result, response.result.value) {
case (.failure(let error), _):
switch error {
case let error as AFError where error.isResponseSerializationError:
DispatchQueue.main.async{
completion(nil, nil)
}
case let error as AFError where error.isResponseValidationError:
switch (error.responseCode, response.data) {
case (401, let data?):
if let response = String(data: data, encoding: .utf8), let reason = SubscriptionError.UnauthorisationReason(rawValue: response) {
DispatchQueue.main.async{
completion(nil, SubscriptionError.unauthorised(reason:reason))
}
} else {
DispatchQueue.main.async{
completion(nil, SubscriptionError.unauthorised(reason: nil))
}
}