title: AFNetworking 2.0 AFHTTPSessionManager: how to get status code and response JSON in failure block?
body: <p>When switched to AFNetworking 2.0 the AFHTTPClient has been replaced by AFHTTPRequestOperationManager / AFHTTPSessionManager (as mentioned in the migration guide). The very first issue I came across when using the AFHTTPSessionManager is how to retrieve the body of the response in the failure block?</p>
  
  <p>Here's an example:
  </p>
  
  <pre><code>[self.sessionManager POST:[endpoint absoluteString] parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
      // How to get the status code?
  } failure:^(NSURLSessionDataTask *task, NSError *error) {
      // How to get the status code? response?
  }];
  </code></pre>
  
  <p>In the success block I would like to retrieve response's status code.
  In the failure block I would like to retrieve both response's status code and the content (which is JSON in this case that describes the server-side error).</p>
  
  <p>The NSURLSessionDataTask has a response property of type NSURLResponse, which has not statusCode field. Currently I'm able to retrieve statusCode like this:</p>
  
  
  
  <pre><code>[self.sessionManager POST:[endpoint absoluteString] parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
      // How to get the status code?
  } failure:^(NSURLSessionDataTask *task, NSError *error) {
      NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
      DDLogError(@"Response statusCode: %i", response.statusCode);
  
  }];
  </code></pre>
  
  <p>But this looks ugly to me. And still can't figure about the response's body.</p>
  
  <p>Any suggestions?</p>