I'm working on a company project who use Alamofire to connect to a Dittofi API.
I'm getting a 0 status code and a weirdly null output. Heres the code (I can only release this as per my NDA):
self.manager.upload(multipartFormData: {
multipartFormData in
for (key, value) in params{
multipartFormData.append(value.data(using: .utf8)!, withName: key)
}
}, to: createAssignmentURL, encodingCompletion: {
(result) in
switch result {
case .success(let upload, _, _):
upload.responseJSON {
response in
switch response.result {
case .success(let j):
let json = JSON(j)
print("JSON: ", json)
let message = json["statusMessage"].stringValue
let status = json["statusCode"].intValue
let data = json["data"]
if status == 200{
completion(message,"",status)
}else{
let errorMessage = data["error_msgs"].stringValue
self.reportError(message: errorMessage)
completion(errorMessage,"",status)
}
case .failure(let error):
if error._code == NSURLErrorTimedOut {
completion(App.CONNECTION_TIMEOUT,"",App.STATUS_TIMEOUT)
}
else if error._code == NSFileNoSuchFileError {
completion(App.INVALID_RESPONSE,"",App.STATUS_INVALID_RESPONSE)
}
else {
completion(App.INVALID_RESPONSE,"",App.STATUS_INVALID_RESPONSE)
}
}
}
case .failure(let error):
if error._code == NSURLErrorTimedOut {
completion(App.CONNECTION_TIMEOUT,"",App.STATUS_TIMEOUT)
}
else if error._code == NSFileNoSuchFileError {
completion(App.INVALID_RESPONSE,"",App.STATUS_INVALID_RESPONSE)
}
else {
completion(App.INVALID_RESPONSE,"",App.STATUS_INVALID_RESPONSE)
}
}
})
Heres the output:
JSON: {
"data" : null,
"error" : {
"message" : "",
"param" : "",
"code" : "e_invalid_json"
}
}
I'm certain something is wrong with the way I post but I cant seem to figure it out. I also get a 0 status code which apparently means that the response is empty. Is this a problem with my code or the API?