Skip to content

Commit

Permalink
Merge pull request #196 from vineetchoudhary/develop
Browse files Browse the repository at this point in the history
Updated Network Errors + Automatic retry option if Create Shared URL failed
  • Loading branch information
vineetchoudhary authored Jun 4, 2020
2 parents 82912fd + 7b17148 commit 38c13fe
Show file tree
Hide file tree
Showing 1,435 changed files with 144,155 additions and 58,501 deletions.
2 changes: 2 additions & 0 deletions AppBox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@
LD_DYLIB_INSTALL_NAME = "";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 2.9.1;
PRODUCT_BUNDLE_IDENTIFIER = com.developerinsider.AppBox;
PRODUCT_NAME = "$(TARGET_NAME)";
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)";
Expand Down Expand Up @@ -1722,6 +1723,7 @@
LD_DYLIB_INSTALL_NAME = "";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.11;
MARKETING_VERSION = 2.9.1;
PRODUCT_BUNDLE_IDENTIFIER = com.developerinsider.AppBox;
PRODUCT_NAME = "$(TARGET_NAME)";
USER_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)";
Expand Down
10 changes: 3 additions & 7 deletions AppBox.xcodeproj/xcshareddata/xcschemes/AppBox.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,8 @@
ReferencedContainer = "container:AppBox.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down Expand Up @@ -83,8 +81,6 @@
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion AppBox/Common/Common.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ + (NSString*)generateUUID {
+ (NSURL *)getFileDirectoryForFilePath:(NSURL *)filePath{
NSArray *pathComponents = [filePath.relativePath pathComponents];
NSString *fileDirectory = [NSString pathWithComponents:[pathComponents subarrayWithRange:NSMakeRange(0, pathComponents.count - 1)]];
fileDirectory = [fileDirectory stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
fileDirectory = [fileDirectory stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
return [NSURL URLWithString:fileDirectory];
}

Expand Down
2 changes: 1 addition & 1 deletion AppBox/Common/DBErrorHandler/DBErrorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@interface DBErrorHandler : NSObject

+(void)handleNetworkErrorWith:(DBRequestError *)networkError;
+(void)handleNetworkErrorWith:(DBRequestError *)networkError abErrorMessage:(NSString *)abErrorMessage;
+(void)handleDeleteErrorWith:(DBFILESDeleteError *)deleteError;
+(void)handleUploadErrorWith:(DBFILESUploadError *)uploadError;
+(void)handleUploadSessionLookupError:(DBFILESUploadSessionLookupError *)error;
Expand Down
107 changes: 65 additions & 42 deletions AppBox/Common/DBErrorHandler/DBErrorHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,71 @@

@implementation DBErrorHandler

+(void)handleNetworkErrorWith:(DBRequestError *)networkError{
switch (networkError.tag) {
case DBRequestErrorAuth:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to invalid authentication credentials. Please login Again."];
[[NSNotificationCenter defaultCenter] postNotificationName:abDropBoxLoggedOutNotification object:self];
}break;

case DBRequestErrorHttp:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors produced at the HTTP layer. Please try again."];
}break;

case DBRequestErrorAccess:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to invalid permission to access."];
}break;

case DBRequestErrorClient:{
if (![[AppDelegate appDelegate] isInternetConnected]){
[Common showNoInternetConnectionAvailabeAlert];
} else {
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to a problem on the client-side of the SDK. Please try again."];
}
}break;

case DBRequestErrorBadInput:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to bad input parameters to an API Operation. Please report the issue."];
}break;

case DBRequestErrorPathRoot:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to invalid authentication credentials."];
}break;

case DBRequestErrorRateLimit:{
[Common showAlertWithTitle:@"Error" andMessage:@"Error caused by rate limiting."];
}break;

case DBRequestErrorInternalServer:{
[Common showAlertWithTitle:@"Error" andMessage:@"Errors due to a problem on Dropbox. Please try again."];
}break;

default:{
[Common showAlertWithTitle:@"Error" andMessage:@"Something goes wrong. Please try again."];
}break;
+(void)handleNetworkErrorWith:(DBRequestError *)networkError abErrorMessage:(NSString *)abErrorMessage {
NSMutableString *errorMessage = [[NSMutableString alloc] init];
if (networkError) {
[errorMessage appendFormat:@"\n\nDropbox Request Error - "];
[errorMessage appendFormat:@"\nError Content - %@", networkError.errorContent];
[errorMessage appendFormat:@"\nStatus Code - %@", networkError.statusCode];
[errorMessage appendFormat:@"\nRequest Id - %@", networkError.requestId];
if (abErrorMessage) {
[errorMessage appendFormat:@"\n\nAppBox Error - %@", abErrorMessage];
}

switch (networkError.tag) {
case DBRequestErrorAuth:{
[errorMessage insertString:@"Errors due to invalid authentication credentials. Please login Again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
[[NSNotificationCenter defaultCenter] postNotificationName:abDropBoxLoggedOutNotification object:self];
}break;

case DBRequestErrorHttp:{
[errorMessage insertString:@"Errors produced at the HTTP layer. Please check following details and try again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

case DBRequestErrorAccess:{
[errorMessage insertString:@"Errors due to invalid permission to access." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

case DBRequestErrorClient:{
if (![[AppDelegate appDelegate] isInternetConnected]){
[Common showNoInternetConnectionAvailabeAlert];
} else {
[errorMessage insertString:@"Errors due to a problem on the client-side of the SDK. Please check following details and try again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}
}break;

case DBRequestErrorBadInput:{
[errorMessage insertString:@"Errors due to bad input parameters to an API Operation. Please report the issue." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

case DBRequestErrorPathRoot:{
[errorMessage insertString:@"Errors due to invalid authentication credentials." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

case DBRequestErrorRateLimit:{
[errorMessage insertString:@"Error caused by rate limiting." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

case DBRequestErrorInternalServer:{
[errorMessage insertString:@"Errors due to a problem on Dropbox Server. Please try again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;

default:{
[errorMessage insertString:@"Something goes wrong. Please try again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}break;
}
} else {
[errorMessage insertString:@"Something goes wrong. Please try again." atIndex:0];
[Common showAlertWithTitle:@"Error" andMessage:errorMessage];
}
}

Expand Down
39 changes: 30 additions & 9 deletions AppBox/Common/UploadManager/UploadManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ +(void)setupDBClientsManager{
}
}

- (instancetype)init
{
- (instancetype)init {
self = [super init];
if (self) {
retryCount = 0;
Expand Down Expand Up @@ -230,7 +229,7 @@ -(void)handleAfterUniqueJsonMetaDataLoaded{
else if (error){
if (self.uploadRecord) {
self.errorBlock(error.nsError, NO);
[DBErrorHandler handleNetworkErrorWith:error];
[DBErrorHandler handleNetworkErrorWith:error abErrorMessage:@"Unable to fetch app records from Dropbox."];
}
//create new appinfo.json
[self handleAfterUniqueJsonMetaDataLoaded];
Expand Down Expand Up @@ -412,6 +411,9 @@ -(void)dbUploadFile:(NSString *)file to:(NSString *)path mode:(DBFILESWriteMode
//Track response with result and error
setResponseBlock:^(DBFILESFileMetadata * _Nullable response, DBFILESUploadError * _Nullable routeError, DBRequestError * _Nullable error) {
if (response) {
//reset retry count
retryCount = 0;

[ABLog log:@"Uploaded file metadata = %@", response];

//AppInfo.json file uploaded and creating shared url
Expand Down Expand Up @@ -500,6 +502,9 @@ -(void)uploadNextChunk{
if (nextChunkToUpload.length < chunkSize) {
[[[[DBClientsManager authorizedClient].filesRoutes uploadSessionFinishData:cursor commit:fileCommitInfo inputData:nextChunkToUpload] setResponseBlock:^(DBFILESFileMetadata * _Nullable result, DBFILESUploadSessionFinishError * _Nullable routeError, DBRequestError * _Nullable networkError) {
if (result) {
//reset retry count
retryCount = 0;

if (self.dbFileType == DBFileTypeIPA){
NSString *status = [NSString stringWithFormat:@"Creating Sharable Link for IPA"];
[self showStatus:status andShowProgressBar:YES withProgress:-1];
Expand Down Expand Up @@ -568,7 +573,7 @@ -(void)handleChunkUploadWithLookupError:(DBFILESUploadSessionLookupError * _Null
} else if (uploadError) {
[DBErrorHandler handleUploadErrorWith:uploadError];
} else {
[DBErrorHandler handleNetworkErrorWith:networkError];
[DBErrorHandler handleNetworkErrorWith:networkError abErrorMessage:nil];
}
}
}
Expand Down Expand Up @@ -606,6 +611,8 @@ -(void)dbGetSharedURLForFile:(NSString *)file{

-(void)handleSharedURLError:(DBRequestError *)error forFile:(NSString *)file{
[[AppDelegate appDelegate] addSessionLog:[NSString stringWithFormat:@"Create Share Link Error - %@",error]];

//Handle clint side SDK error
if ([error isClientError]){
if ([[AppDelegate appDelegate] isInternetConnected]){
[self dbCreateSharedURLForFile:file];
Expand All @@ -614,13 +621,27 @@ -(void)handleSharedURLError:(DBRequestError *)error forFile:(NSString *)file{
[self dbCreateSharedURLForFile:file];
}];
}
}else if([error isHttpError] && error.statusCode.integerValue == 409){
}

//Retry upload if there is any conflict in file upload
else if([error isHttpError] && error.statusCode.integerValue == 409 && retryCount < abOnErrorMaxRetryCount){
[self dbGetSharedURLForFile:file];
}else{
}

//Handle DB Client and Server error by Retrying Upto 3 times
else if (retryCount < abOnErrorMaxRetryCount) {
retryCount++;
[self dbCreateSharedURLForFile:file];
[[AppDelegate appDelegate] addSessionLog: [NSString stringWithFormat:@"Retrying (%ld) Shared URL due to some error.", (long)retryCount]];
}

//Handle other errors
else {
if (self.ciRepoProject) {
exit(abExitCodeForUploadFailed);
}
[DBErrorHandler handleNetworkErrorWith:error];
retryCount = 0;
[DBErrorHandler handleNetworkErrorWith:error abErrorMessage:@"Unable to create a share URL for the file."];
self.errorBlock(nil, YES);
}
}
Expand Down Expand Up @@ -729,7 +750,7 @@ -(void)deleteBuildFolder{
} else if (routeError) {
[DBErrorHandler handleDeleteErrorWith:routeError];
} else if (networkError) {
[DBErrorHandler handleNetworkErrorWith:networkError];
[DBErrorHandler handleNetworkErrorWith:networkError abErrorMessage:@"Unable to delete build folder."];
}
}];
}
Expand All @@ -742,7 +763,7 @@ -(void)deleteBuildRootFolder{
} else if (routeError) {
[DBErrorHandler handleDeleteErrorWith:routeError];
} else if (networkError) {
[DBErrorHandler handleNetworkErrorWith:networkError];
[DBErrorHandler handleNetworkErrorWith:networkError abErrorMessage:@"Unable to delete file."];
}
}];
}
Expand Down
2 changes: 1 addition & 1 deletion AppBox/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.9.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down
4 changes: 2 additions & 2 deletions AppBox/Model/ProjectModel/XCProject.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (void)createBuildRelatedPathsAndIsNew:(BOOL)isNew{

//Build UUID Path
NSString *buildUUIDPath = [_buildDirectory.resourceSpecifier stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-%@",self.name, currentTime]];
NSString* escapedBuildUUIDPath = [buildUUIDPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSString* escapedBuildUUIDPath = [buildUUIDPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]];
_buildUUIDDirectory = [NSURL URLWithString:escapedBuildUUIDPath];
[[NSFileManager defaultManager] createDirectoryAtPath:buildUUIDPath withIntermediateDirectories:NO attributes:nil error:nil];

Expand All @@ -104,7 +104,7 @@ - (void)createBuildRelatedPathsAndIsNew:(BOOL)isNew{

//IPA Path
NSString *ipaPath = [_buildUUIDDirectory.resourceSpecifier stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.ipa", self.selectedSchemes]];
_ipaFullPath = [NSURL URLWithString:[ipaPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
_ipaFullPath = [NSURL URLWithString:[ipaPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]];

//Export Option Plist
NSString *exportOptionPlistPath = [_buildUUIDDirectory.resourceSpecifier stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-ExportOptions.plist", self.name]];
Expand Down
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ source 'https://cdn.cocoapods.org/'
inhibit_all_warnings!

target :AppBox do
pod 'ISO8601'
pod 'AFNetworking'
pod 'SSZipArchive'
pod 'CMDQueryStringSerialization'
Expand Down
Loading

0 comments on commit 38c13fe

Please sign in to comment.