1
0
mirror of https://github.com/lint/TFDidThatSay synced 2025-07-03 08:16:47 +00:00

More descriptive error messages

This commit is contained in:
lint
2020-11-05 20:41:35 -05:00
parent 0a5a220db0
commit 81d08d5e87

View File

@ -6,7 +6,7 @@
+ (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel { + (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel {
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; //NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if (isComment){ if (isComment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
@ -17,27 +17,31 @@
[request setHTTPMethod:@"GET"]; [request setHTTPMethod:@"GET"];
[request setTimeoutInterval:timeout]; [request setTimeoutInterval:timeout];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]"; NSString *author = @"[author]";
NSString *body = @"[body]"; NSString *body = @"[body]";
if (data != nil && error == nil){ if (data) {
id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"]; id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
if ([jsonData count] != 0){ if (jsonData && [jsonData count] != 0) {
author = [jsonData[0] objectForKey:@"author"]; author = [jsonData[0] objectForKey:@"author"];
body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"]; body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){ if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]"; body = [NSString stringWithFormat:@"[pushshift was unable to archive this %@]", isComment ? @"comment" : @"post"];
} }
} else { } else {
body = @"[pushshift has not archived this yet]"; body = [NSString stringWithFormat:@"[no data for this %@ was returned by pushshift]", isComment ? @"comment" : @"post"];
} }
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
} }
NSMutableDictionary *result = [@{@"author" : author, @"body" : body} mutableCopy]; if (error) {
body = [NSString stringWithFormat:@"[an error occurred while attempting retrieve data from the pushshift api]\n\nHTTP Status Code: %li\n\nError Description: %@",
(long)((NSHTTPURLResponse *)response).statusCode, [error localizedDescription]];
}
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:@{@"author" : author, @"body" : body}];
if (extra){ if (extra){
[result addEntriesFromDictionary:extra]; [result addEntriesFromDictionary:extra];
@ -45,6 +49,7 @@
[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO]; [target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
}]; }];
[dataTask resume];
} }
+ (BOOL)shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{ + (BOOL)shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{