Permalink
Browse files

Cause a failure when an operation is cancelled, fixes #657

  • Loading branch information...
1 parent a146a3b commit 7134e9612f0cd2865a4624000147f62e74e5fe45 @danielctull danielctull committed Dec 19, 2012
View
4 AFNetworking/AFHTTPRequestOperation.m
@@ -273,10 +273,6 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operatio
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
self.completionBlock = ^{
- if ([self isCancelled]) {
- return;
- }
-
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
View
4 AFNetworking/AFImageRequestOperation.m
@@ -203,10 +203,6 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operatio
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
dispatch_async(image_request_operation_processing_queue(), ^(void) {
if (self.error) {
if (failure) {
View
6 AFNetworking/AFJSONRequestOperation.m
@@ -104,11 +104,7 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operatio
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
View
6 AFNetworking/AFPropertyListRequestOperation.m
@@ -108,11 +108,7 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operatio
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
if (self.error) {
if (failure) {
dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
View
13 AFNetworking/AFURLConnectionOperation.m
@@ -453,15 +453,18 @@ - (void)cancel {
}
- (void)cancelConnection {
+
+ NSDictionary *userInfo = nil;
+ if ([self.request URL]) {
+ userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
+ }
+ self.error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo];
+
if (self.connection) {
[self.connection cancel];
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
- NSDictionary *userInfo = nil;
- if ([self.request URL]) {
- userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
- }
- [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]];
+ [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.error];
}
}
View
6 AFNetworking/AFXMLRequestOperation.m
@@ -140,11 +140,7 @@ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operatio
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
- self.completionBlock = ^ {
- if ([self isCancelled]) {
- return;
- }
-
+ self.completionBlock = ^ {
dispatch_async(xml_request_operation_processing_queue(), ^(void) {
NSXMLParser *XMLParser = self.responseXMLParser;

0 comments on commit 7134e96

Please sign in to comment.