Skip to content

Commit 699ad6e

Browse files
Fix breaking changes of latest dropbox SDK
1 parent df9e95f commit 699ad6e

3 files changed

Lines changed: 61 additions & 13 deletions

File tree

AppBox/Common/DBErrorHandler/DBErrorHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
+(void)handleUploadErrorWith:(DBFILESUploadError *)uploadError;
1616
+(void)handleUploadSessionLookupError:(DBFILESUploadSessionLookupError *)error;
1717
+(void)handleUploadSessionFinishError:(DBFILESUploadSessionFinishError *)error;
18+
+(void)handleUploadSessionAppendError:(DBFILESUploadSessionAppendError *)error;
1819

1920
@end

AppBox/Common/DBErrorHandler/DBErrorHandler.m

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,53 @@ +(void)handleUploadSessionLookupError:(DBFILESUploadSessionLookupError *)error{
149149
}
150150
}
151151

152+
+(void)handleUploadSessionAppendError:(DBFILESUploadSessionAppendError *)error {
153+
switch (error.tag) {
154+
case DBFILESUploadSessionAppendErrorNotFound: {
155+
[Common showAlertWithTitle:@"Error" andMessage:@"Upload session not found. Please try again."];
156+
}break;
157+
158+
case DBFILESUploadSessionAppendErrorIncorrectOffset: {
159+
[Common showAlertWithTitle:@"Error" andMessage:@"Offset is incorrect for the upload session. Please try again."];
160+
}break;
161+
162+
case DBFILESUploadSessionAppendErrorClosed: {
163+
[Common showAlertWithTitle:@"Error" andMessage:@"Upload session closed. Please try again."];
164+
}break;
165+
166+
case DBFILESUploadSessionAppendErrorNotClosed: {
167+
[Common showAlertWithTitle:@"Error" andMessage:@"Upload session not closed. Please try again."];
168+
}break;
169+
170+
case DBFILESUploadSessionAppendErrorTooLarge: {
171+
[Common showAlertWithTitle:@"Error" andMessage:@"The file size is too large. Please try again."];
172+
}break;
173+
174+
case DBFILESUploadSessionAppendErrorConcurrentSessionInvalidOffset: {
175+
[Common showAlertWithTitle:@"Error" andMessage:@"Invalid offset for the concurrent session. Please try again."];
176+
}break;
177+
178+
case DBFILESUploadSessionAppendErrorConcurrentSessionInvalidDataSize: {
179+
[Common showAlertWithTitle:@"Error" andMessage:@"Invalid data size for the concurrent session. Please try again."];
180+
}break;
181+
182+
case DBFILESUploadSessionAppendErrorPayloadTooLarge: {
183+
[Common showAlertWithTitle:@"Error" andMessage:@"The payload size is too large. Please try again."];
184+
}break;
185+
186+
case DBFILESUploadSessionAppendErrorOther: {
187+
[Common showAlertWithTitle:@"Error" andMessage:@"Something goes wrong. Please try again."];
188+
}break;
189+
190+
case DBFILESUploadSessionAppendErrorContentHashMismatch: {
191+
[Common showAlertWithTitle:@"Error" andMessage:@"The content hash does not match. Please try again."];
192+
}break;
193+
194+
default:
195+
break;
196+
}
197+
}
198+
152199
+(void)handleUploadSessionFinishError:(DBFILESUploadSessionFinishError *)error{
153200
switch (error.tag) {
154201
case DBFILESUploadSessionFinishErrorPath:{

AppBox/Common/UploadManager/UploadManager.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ -(void)dbUploadFile:(NSString *)file to:(NSString *)path mode:(DBFILESWriteMode
369369

370370
//uploadUrl:path inputUrl:file
371371
weakify(self);
372-
[[[[DBClientsManager authorizedClient].filesRoutes uploadUrl:path mode:mode autorename:@NO clientModified:nil mute:@NO propertyGroups:nil strictConflict:@NO inputUrl:file]
372+
[[[[DBClientsManager authorizedClient].filesRoutes uploadUrl:path mode:mode autorename:@NO clientModified:nil mute:@NO propertyGroups:nil strictConflict:@NO contentHash:nil inputUrl:file]
373373
//Track response with result and error
374374
setResponseBlock:^(DBFILESFileMetadata * _Nullable response, DBFILESUploadError * _Nullable routeError, DBRequestError * _Nullable error) {
375375
strongify(self);
@@ -414,7 +414,7 @@ -(void)dbUploadFile:(NSString *)file to:(NSString *)path mode:(DBFILESWriteMode
414414
//unable to upload file, show error
415415
else {
416416
NSBlockOperation *retryOperation = [NSBlockOperation blockOperationWithBlock:^{ [self dbUploadFile:file to:path mode:mode]; }];
417-
[self handleChunkUploadWithLookupError:nil finishError:nil uploadError:nil networkError:error retryBlock:retryOperation];
417+
[self handleChunkUploadWithRouteError:nil finishError:nil uploadError:nil networkError:error retryBlock:retryOperation];
418418
}
419419
}]
420420

@@ -455,7 +455,7 @@ -(void)dbUploadLargeFile:(NSString *)file to:(NSString *)path mode:(DBFILESWrite
455455
[self uploadNextChunk];
456456
} else {
457457
NSBlockOperation *retryOperation = [NSBlockOperation blockOperationWithBlock:^{ [self dbUploadLargeFile:file to:path mode:mode]; }];
458-
[self handleChunkUploadWithLookupError:nil finishError:nil uploadError:nil networkError:networkError retryBlock:retryOperation];
458+
[self handleChunkUploadWithRouteError:nil finishError:nil uploadError:nil networkError:networkError retryBlock:retryOperation];
459459
}
460460
}] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
461461
[self updateProgressBytesWritten:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
@@ -483,21 +483,21 @@ -(void)uploadNextChunk{
483483
}
484484
} else {
485485
NSBlockOperation *retryOperation = [NSBlockOperation blockOperationWithBlock:^{ [self uploadNextChunk]; }];
486-
[self handleChunkUploadWithLookupError:nil finishError:routeError uploadError:nil networkError:networkError retryBlock:retryOperation];
486+
[self handleChunkUploadWithRouteError:nil finishError:routeError uploadError:nil networkError:networkError retryBlock:retryOperation];
487487
}
488488
}] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
489489
strongify(self);
490490
[self updateProgressBytesWritten:bytesWritten totalBytesWritten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
491491
}];
492492
} else {
493-
[[[[DBClientsManager authorizedClient].filesRoutes uploadSessionAppendV2Data:cursor inputData:nextChunkToUpload] setResponseBlock:^(DBNilObject * _Nullable result, DBFILESUploadSessionLookupError * _Nullable routeError, DBRequestError * _Nullable networkError) {
493+
[[[[DBClientsManager authorizedClient].filesRoutes uploadSessionAppendV2Data:cursor inputData:nextChunkToUpload] setResponseBlock:^(DBNilObject * _Nullable result, DBFILESUploadSessionAppendError * _Nullable routeError, DBRequestError * _Nullable networkError) {
494494
strongify(self);
495495
if (result) {
496496
self->offset += self->nextChunkToUpload.length;
497497
[self uploadNextChunk];
498498
} else {
499499
NSBlockOperation *retryOperation = [NSBlockOperation blockOperationWithBlock:^{ [self uploadNextChunk]; }];
500-
[self handleChunkUploadWithLookupError:routeError finishError:nil uploadError:nil networkError:networkError retryBlock:retryOperation];
500+
[self handleChunkUploadWithRouteError:routeError finishError:nil uploadError:nil networkError:networkError retryBlock:retryOperation];
501501
}
502502
}] setProgressBlock:^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
503503
strongify(self);
@@ -508,11 +508,11 @@ -(void)uploadNextChunk{
508508

509509
#pragma mark - Upload File Helper
510510
//Helper to Handle Chunk Upload Error
511-
-(void)handleChunkUploadWithLookupError:(DBFILESUploadSessionLookupError * _Nullable)lookupError
512-
finishError:(DBFILESUploadSessionFinishError * _Nullable)finishError
513-
uploadError:(DBFILESUploadError * _Nullable)uploadError
514-
networkError:(DBRequestError * _Nullable)networkError
515-
retryBlock:(NSBlockOperation *)operation{
511+
-(void)handleChunkUploadWithRouteError:(DBFILESUploadSessionAppendError * _Nullable)routeError
512+
finishError:(DBFILESUploadSessionFinishError * _Nullable)finishError
513+
uploadError:(DBFILESUploadError * _Nullable)uploadError
514+
networkError:(DBRequestError * _Nullable)networkError
515+
retryBlock:(NSBlockOperation *)operation {
516516
//Handle Internet Connection Lost
517517
if (networkError && networkError.nsError.code == -1009) {
518518
self.lastfailedOperation = operation;
@@ -538,8 +538,8 @@ -(void)handleChunkUploadWithLookupError:(DBFILESUploadSessionLookupError * _Null
538538
self.errorBlock(nil, YES);
539539

540540
//Handle Route and Network Errors
541-
if (lookupError) {
542-
[DBErrorHandler handleUploadSessionLookupError:lookupError];
541+
if (routeError) {
542+
[DBErrorHandler handleUploadSessionAppendError:routeError];
543543
} else if (finishError) {
544544
[DBErrorHandler handleUploadSessionFinishError:finishError];
545545
} else if (uploadError) {

0 commit comments

Comments
 (0)