dropbox errors now display error summary

This commit is contained in:
Kilian Hofmann 2016-04-04 09:57:20 +02:00
parent a41b939b99
commit b2aed3d958
3 changed files with 114 additions and 22 deletions

View File

@ -102,16 +102,22 @@
options:0 options:0
error:nil] error:nil]
isEqualToDictionary:@{}]) { isEqualToDictionary:@{}]) {
[SharedDeclerations [[NSOperationQueue mainQueue] addOperationWithBlock:^{
presentErrorAlert: [SharedDeclerations
[NSError errorWithDomain:DropboxErrorDomain presentErrorAlert:
code:100 [NSError
userInfo:@{ errorWithDomain:DropboxErrorDomain
DropboxErrorUserInfo : code:100
NSLocalizedDescriptionKey userInfo:
}] [[NSJSONSerialization
JSONObjectWithData:data
options:0
error:nil]
valueForKey:
DropboxErrorUserInfo]]
presenter:presenter]; presenter:presenter];
}];
} }
}]; }];
@ -122,7 +128,6 @@
* Pass nil as path for root dir * Pass nil as path for root dir
* @param completion executed after completion * @param completion executed after completion
*/ */
// TODO: Alert on Dropbox error
- (void)contentsOfPath:(NSString *)path - (void)contentsOfPath:(NSString *)path
completion:(void (^)(NSArray *data))handler completion:(void (^)(NSArray *data))handler
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
@ -160,7 +165,7 @@
[NSURLConnection [NSURLConnection
sendAsynchronousRequest:request sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue] queue:[[NSOperationQueue alloc] init]
completionHandler:^(NSURLResponse *response, NSData *data, completionHandler:^(NSURLResponse *response, NSData *data,
NSError *error) { NSError *error) {
if (data != nil) { if (data != nil) {
@ -168,7 +173,31 @@
options:0 options:0
error:nil]; error:nil];
if ([data isKindOfClass:[NSDictionary class]]) { if ([data isKindOfClass:[NSDictionary class]]) {
handler([data valueForKey:@"entries"]); NSArray *data2 = [data valueForKey:@"entries"];
if (data2 == nil) {
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:
[[NSJSONSerialization
JSONObjectWithData:
data
options:
0
error:
nil]
valueForKey:
DropboxErrorUserInfo]]
presenter:presenter];
}];
}
else {
handler(data2);
}
} }
} }
else if (error != nil) { else if (error != nil) {
@ -182,7 +211,6 @@
}]; }];
} }
// TODO: Alert on Dropbox error
- (void)downloadFromDropbox:(NSArray *)files - (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter presenter:(UIViewController *)presenter
{ {
@ -221,9 +249,35 @@
completionHandler:^(NSURLResponse *response, NSData *data, completionHandler:^(NSURLResponse *response, NSData *data,
NSError *error) { NSError *error) {
if (error == nil) { if (error == nil) {
[data writeToFile:[SharedDeclerations if ([[NSJSONSerialization JSONObjectWithData:data
savePathForFile:string] options:0
atomically:YES]; error:nil]
valueForKey:@"error_summary"] == nil) {
[data writeToFile:[SharedDeclerations
savePathForFile:string]
atomically:YES];
}
else {
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:
[[NSJSONSerialization
JSONObjectWithData:
data
options:
0
error:
nil]
valueForKey:
DropboxErrorUserInfo]]
presenter:presenter];
}];
}
} }
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
@ -238,7 +292,6 @@
} }
} }
// TODO: Alert on Dropbox error
- (void)uploadToDropbox:(NSArray *)files presenter:(UIViewController *)presenter - (void)uploadToDropbox:(NSArray *)files presenter:(UIViewController *)presenter
{ {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
@ -287,6 +340,26 @@
}]; }];
} }
if ([[NSJSONSerialization JSONObjectWithData:data
options:0
error:nil]
valueForKey:@"error_summary"] != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations
presentErrorAlert:
[NSError
errorWithDomain:DropboxErrorDomain
code:100
userInfo:
[[NSJSONSerialization
JSONObjectWithData:data
options:0
error:nil]
valueForKey:
DropboxErrorUserInfo]]
presenter:presenter];
}];
}
}]; }];
} }
} }
@ -294,7 +367,6 @@
#pragma mark - Other operations #pragma mark - Other operations
// !!!: Cannot be asynchronous // !!!: Cannot be asynchronous
// TODO: Alert on Dropbox error
- (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter - (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter
{ {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
@ -319,7 +391,26 @@
returningResponse:&response returningResponse:&response
error:&error2]]; error:&error2]];
if ([data isKindOfClass:[NSDictionary class]]) { if ([data isKindOfClass:[NSDictionary class]]) {
return data; if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
valueForKey:@"error_summary"] == nil) {
return data;
}
else {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[SharedDeclerations
presentErrorAlert:
[NSError errorWithDomain:DropboxErrorDomain
code:100
userInfo:[[NSJSONSerialization
JSONObjectWithData:data
options:0
error:nil]
valueForKey:
DropboxErrorUserInfo]]
presenter:presenter];
}];
return nil;
}
} }
else if (error != nil) { else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ [[NSOperationQueue mainQueue] addOperationWithBlock:^{

View File

@ -13,8 +13,7 @@
NSString *const FMCNEXTRTEPAGE = @"NEXTRTEPAGE"; NSString *const FMCNEXTRTEPAGE = @"NEXTRTEPAGE";
NSString *const FMCFIRSTRTEPAGE = @"FIRSTRTEPAGE"; NSString *const FMCFIRSTRTEPAGE = @"FIRSTRTEPAGE";
NSString *const DropboxErrorDomain = @"com.weebly.alikja.FMC"; NSString *const DropboxErrorDomain = @"com.weebly.alikja.FMC";
NSString *const DropboxErrorUserInfo = NSString *const DropboxErrorUserInfo = @"error_summary";
@"Dropbox API Error. Please try again later!";
#pragma mark - Adaptive font size method #pragma mark - Adaptive font size method

View File

@ -55,7 +55,9 @@ DropboxV2ObjC *dbClient = nil;
[NSPredicate [NSPredicate
predicateWithFormat:@"NOT (SELF BEGINSWITH %@)", predicateWithFormat:@"NOT (SELF BEGINSWITH %@)",
@"."]] mutableCopy]; @"."]] mutableCopy];
[self.tableView reloadData]; [[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.tableView reloadData];
}];
} }
presenter:self]; presenter:self];
} }