RKObjectLoader's response is empty in didFailWithError #527

Closed
nickdaugherty opened this Issue Jan 24, 2012 · 4 comments

Projects

None yet

4 participants

@nickdaugherty

If you attempt to access an RKObjectLoader's response property in your RKObjectLoaderDelegate's - (void) objectLoader:(RKObjectLoader *)objectLoader didFailWithError:(NSError *)error it is always null. It would be very useful to have the full response here, to detect exactly what the error was. Is this a bug or am I missing something?

@jeffarena
Member

Would be great if you had a failing test showing the response property being nil, as that is not expected behavior.

@nickdaugherty

I don't have a test but could be related to the fact that I'm using HTTP authentication, and the authentication is failing? I'm returning a HTTP 401 from my api to test auth failures. With RK logging turned on, I get 'Failed authentication challenge after 1 failures', which is expected. Then if I attempt to log the objectLoader's response object with:

NSLog(@"response is %@", objectLoader.response);

I get 'response is (null)' in gdb. Likewise, if I set a breakpoint and inspect the objectLoader variable, it says the response member is 0x0.

I have a feeling this comes from the 401 response code, but that's just a guess.

@bmorton
bmorton commented Mar 11, 2012

I've been working on replicating this in the test suite and I think I understand what's happening. RKObjectLoader is a subclass of RKRequest. RKObjectManager builds an objectLoader and calls send (contained in RKRequest, which then trickles down to sendAsynchronously.) RKRequest doesn't implement a response property, but RKObjectLoader does. Since the response object is built strictly in RKRequest, it can't populate RKObjectLoader's response property. An RKObjectLoader object only finds out about the response after RKResponse fires a didFinishLoad: on its request object and passes itself back. If an error occurs, it never sees the response so it returns nil.

We can either move the response property to RKRequest so that the send methods can populate it or we can have RKResponse return itself when we call didFailLoadWithError: on the request object.

@bmorton
bmorton commented Mar 20, 2012

I've talked this over with @blakewatters a bit and moving the response property to RKRequest seems to be the best attack strategy here. I'm going to assign this to 0.9.5 so we can get this rolling for the next release.

@signalsandstuff signalsandstuff added a commit to signalsandstuff/RestKit that referenced this issue May 31, 2012
@signalsandstuff signalsandstuff Merge branch 'master' of git://github.com/RestKit/RestKit
* 'master' of git://github.com/RestKit/RestKit: (360 commits)
  Fix issue where grouping objects by section in RKTableController and loading an empty collection would fail to refresh table view.
  Fix type mismatch assertion in cases where JSON/XML payload contains a string value for an integer primary key. fixes #754
  Fix static analyzer warning
  Cleanups to and test coverage expansion of RKTableController API's. refs #765
  Update RKTestFactory to silence logging output during setup/tear down operations. closes #764
  Reworked table controller state into a bit mask to coalesce state change into a single observation. fixes #753
  Implemented support for type coercions in primaryKeyAttribute API's. closes #758
  Cancel current object loader when loading a table view
  Clean up inconsistencies with 'cancelled' and 'cancel' to match Cocoa (isCancelled)
  Ensure managed object connections are established across appropriate managed object contexts
  Add RKLog helper for displaying detailed key-value validation failure information. closes #750
  Bump version to 0.10.1
  Fix for RestKit#709 - [RKManagedObjectThreadSafeInvocation serializeManagedObjectsForArgument:withKeyPaths:] is not properly serializing managed objects
  Ensure creation of Application Data directory when initializing Managed Object Store. fixes #657
  Add tests verifying expected behavior for availability of RKRequest response property. closes #527
  Eliminate duplication of request method to string logic in [RKRequest HTTPMethod]
  Migrate RKResponse property from RKObjectLoader to RKRequest. refs #527
  Fix static analyzer issues
  Replace v0.9.4 references with 0.10.0
  Rework intermittently failing tests
  ...

Conflicts:
	Code/Network/RKRequest.m
6b46630
@smclelland smclelland pushed a commit to smclelland/RestKit that referenced this issue Jun 7, 2012
smclelland Merge branch 'master' of git://github.com/RestKit/RestKit
* 'master' of git://github.com/RestKit/RestKit: (109 commits)
  Fix issue where grouping objects by section in RKTableController and loading an empty collection would fail to refresh table view.
  Fix type mismatch assertion in cases where JSON/XML payload contains a string value for an integer primary key. fixes #754
  Fix static analyzer warning
  Cleanups to and test coverage expansion of RKTableController API's. refs #765
  Update RKTestFactory to silence logging output during setup/tear down operations. closes #764
  Reworked table controller state into a bit mask to coalesce state change into a single observation. fixes #753
  Implemented support for type coercions in primaryKeyAttribute API's. closes #758
  Cancel current object loader when loading a table view
  Clean up inconsistencies with 'cancelled' and 'cancel' to match Cocoa (isCancelled)
  Ensure managed object connections are established across appropriate managed object contexts
  Add RKLog helper for displaying detailed key-value validation failure information. closes #750
  Bump version to 0.10.1
  Fix for RestKit#709 - [RKManagedObjectThreadSafeInvocation serializeManagedObjectsForArgument:withKeyPaths:] is not properly serializing managed objects
  Ensure creation of Application Data directory when initializing Managed Object Store. fixes #657
  Add tests verifying expected behavior for availability of RKRequest response property. closes #527
  Eliminate duplication of request method to string logic in [RKRequest HTTPMethod]
  Migrate RKResponse property from RKObjectLoader to RKRequest. refs #527
  Fix static analyzer issues
  Replace v0.9.4 references with 0.10.0
  Rework intermittently failing tests
  ...

Conflicts:
	Code/Support/Parsers/JSON/RKJSONParserJSONKit.m
c126532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment