fix bug, no upload new readings after Internet failure
The bug was that after restore of failed Internet connection, new readings are not uploaded to NS. - as mentioned in the comments of func uploadData(dataToUpload: Any, httpMethod: String?, path: String, completionHandler: (() -> ())?) completionhandler should be called only when upload was successful. But the result of the upload was never checked. So probably, in some error cases, completionhandler was called with success. As a result, the upload was considered as successful and not redone when internet comes back - also some updates in func uploadDataAndGetResponse. Set nightScoutResult to .failed when there was an error.
This commit is contained in:
parent
d76aa72994
commit
c580416e62
|
@ -1047,7 +1047,8 @@ public class NightScoutUploadManager: NSObject {
|
|||
|
||||
uploadDataAndGetResponse(dataToUpload: dataToUpload, httpMethod: httpMethod, path: path) { _, nightScoutResult in
|
||||
|
||||
if let completionHandler = completionHandler {
|
||||
// completion handler to be called only if upload as successful
|
||||
if let completionHandler = completionHandler, nightScoutResult.successFull() {
|
||||
|
||||
completionHandler()
|
||||
|
||||
|
@ -1139,6 +1140,9 @@ public class NightScoutUploadManager: NSObject {
|
|||
// error cases
|
||||
if let error = error {
|
||||
trace(" failed to upload, error = %{public}@", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .error, error.localizedDescription)
|
||||
|
||||
nightScoutResult = NightScoutResult.failed
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1178,18 +1182,26 @@ public class NightScoutUploadManager: NSObject {
|
|||
}
|
||||
|
||||
} catch {
|
||||
// json decode fails, upload will be considered as failed
|
||||
// json decode fails, upload will be considered as failed
|
||||
nightScoutResult = NightScoutResult.failed
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
trace(" failed to upload, statuscode = %{public}@", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .error, response.statusCode.description)
|
||||
|
||||
nightScoutResult = NightScoutResult.failed
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
} else {
|
||||
trace(" response is not HTTPURLResponse", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .error)
|
||||
|
||||
nightScoutResult = NightScoutResult.failed
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// successful cases
|
||||
|
@ -1220,6 +1232,8 @@ public class NightScoutUploadManager: NSObject {
|
|||
|
||||
trace(" error : %{public}@", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .info, error.localizedDescription)
|
||||
|
||||
completionHandler(nil, NightScoutResult.failed)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue