title: objc afnetworking 2.0 show responseObject on error
body: <p>I upload an image via <code>POST request</code> to an <code>server</code>. On success I get a <code>JSON</code> answer back. Unfortunatly an error occurs. I would like to takle this down, but I do not know how to show the respsonse I get from the server when an error occurs. I would like to see the <code>JSON text</code> which <code>did not start with array or object and option to allow fragments not set.</code></p>
  
  <p><strong>How do I show the responsebody (not error-body) of an POST request on failure, by using AFNetworking 2.0?</strong></p>
  
  <pre><code>Error Message:
  &gt; 2013-11-21 16:05:16.479 Foobar[1772:907] -[CameraViewController upload]: uploader  
  &gt; 2013-11-21 16:05:27.275 Foobar[1772:907] Error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x2085aee0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}
  </code></pre>
  
  <h3>CameraViewController.h</h3>
  
  <pre class="lang-c prettyprint-override"><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface CameraViewController : UIViewController &lt;UIImagePickerControllerDelegate, UINavigationControllerDelegate&gt;
  @property (weak, nonatomic) IBOutlet UIImageView *imageView;
  
  @end
  </code></pre>
  
  <h3>CameraViewControllerView.m</h3>
  
  <pre class="lang-c prettyprint-override"><code>#import "CameraViewController.h"
  #import "AFHTTPRequestOperationManager.h"
  
  @interface CameraViewController ()
  
  @property (nonatomic) int photoIsTaken;
  
  @end
  
  @implementation CameraViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
          self.photoIsTaken = 0;
      }
      return self;
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  
  }
  
  -(void)viewDidAppear:(BOOL)animated {
      if (self.photoIsTaken == 0) {
          if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
              // select Photo
          } else {
              [self takePhoto];
          }
      } else {
          [self upload];
      }
  
  }
  
  - (void)takePhoto {
      UIImagePickerController *picker = [[UIImagePickerController alloc] init];
      picker.delegate = self;
      picker.allowsEditing = YES;
      picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  
      [self presentViewController:picker animated:NO completion:NULL];
  }
  
  // [ removed unecessary code for this question ]
  
  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  
      UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
      self.imageView.image = chosenImage;
      self.photoIsTaken = 1;
  
      [picker dismissViewControllerAnimated:YES completion:NULL];
  
  }
  
  - (void)upload {
      NSLog(@"%s: uploader ", __FUNCTION__);
      AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
      NSDictionary *parameters = @{@"latitude": @"8.444444",
                                   @"longitude": @"50.44444",
                                   @"location": @"New York",
                                   @"type": @"2",
                                   @"claim": @"NYC",
                                   @"flag": @"0",
                                   @"file": UIImageJPEGRepresentation(self.imageView.image,30)};
  
      [manager POST:@"http://192.168.1.157/tapp/laravel/public/foobar/upload" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
          NSLog(@"JSON: %@", responseObject);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          NSLog(@"Error: %@", error);
      }];
  
      [self dismissViewControllerAnimated:NO completion:nil];
  }
  
  @end
  </code></pre>