Skip to content

Commit

Permalink
DIGI-17635 : Fixed a bug where session completion would be called pre…
Browse files Browse the repository at this point in the history
…maturely (in … (#139)

* Fixed a bug where session completion would be called prematurely (in case of an error)

* fileList fetch failure will now be reported right away if there are no queued downloads.
  • Loading branch information
alex-yushchenko authored and hamiltonalex committed Oct 23, 2019
1 parent a53e98f commit f99cda4
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions DigiMeSDK/Core/Classes/DMEPullClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @interface DMEPullClient () <DMEPreConsentViewControllerDelegate, DMEAPIClientDe
@property (nonatomic, strong, nullable) void (^sessionContentHandler)(DMEFile * _Nullable file, NSError * _Nullable error);
@property (nonatomic) BOOL fetchingSessionData;
@property (nonatomic) DMEFileList *sessionFileList;
@property (nonatomic) NSError *sessionError;

@end

Expand Down Expand Up @@ -273,21 +274,24 @@ - (void)evaluateSessionDataFetchProgress:(BOOL)schedulePoll
NSLog(@"DigiMeSDK: Sync status - %@", self.sessionFileList.syncStatusString);
}

if (![self syncRunning] && !self.apiClient.isDownloadingFiles)
// If sessionError is not nil, then syncStatus is irrelevant, as it will be the previous successful fileList call.
if ((self.sessionError != nil || ![self syncRunning]) && !self.apiClient.isDownloadingFiles)
{
if (self.configuration.debugLogEnabled)
{
NSLog(@"DigiMeSDK: Finished fetching session data.");
}

[self completeSessionDataFetchWithError:nil];
[self completeSessionDataFetchWithError:self.sessionError];
return;
}
else if (schedulePoll)
{
[self scheduleNextPoll];
}

// not checking sessionError here on purpose. If we are here, then there are files still being downloaded
// so we may as well poll the file list again, just in case the error clears.
if ([self syncRunning])
{
[self refreshFileList];
Expand All @@ -305,10 +309,27 @@ - (void)refreshFileList

if (fileList == nil)
{
[self completeSessionDataFetchWithError:error];
// If the error occurred we don't want to terminate right away
// There could still be files downloading. Instead, we will store the sessionError
// which will be forwarded in completion once all file have been downloaded

if (self.configuration.debugLogEnabled)
{
NSLog(@"DigiMeSDK: Error fetching file list: %@", error.localizedDescription);
}

// If no files are being downloaded, we can terminate session fetch right away.
if (!self.apiClient.isDownloadingFiles)
{
[self completeSessionDataFetchWithError:error];
}

self.sessionError = error;
return;
}

// If subsequent fetch clears the error - great, no need to report it back up the chain
self.sessionError = nil;
self.sessionFileList = fileList;
NSArray <DMEFileListItem *> *newItems = [self.fileCache newItemsFromList:fileList.files];

Expand Down Expand Up @@ -383,6 +404,7 @@ - (void)clearSessionData
self.sessionDataCompletion = nil;
self.sessionContentHandler = nil;
self.apiClient.delegate = nil;
self.sessionError = nil;
}

#pragma mark - Get File Content
Expand Down

0 comments on commit f99cda4

Please sign in to comment.