Reputation: 11514
I am using RestKit 0.2, and I am getting the following error.
E restkit.network:RKObjectRequestOperation.m:237 GET 'http://some.url.com/o/3134' (200 OK / 0 objects) [request=3.2563s mapping=0.0000s total=3.2955s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (400-499), got 200" UserInfo=0x87712e0 {NSLocalizedRecoverySuggestion={"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://some.url.com/o/3134>, NSErrorFailingURLKey=http://some.url.com/o/3134, NSLocalizedDescription=Expected status code in (400-499), got 200, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x9647260>}
I use nodejs and restify as the server end. And I can get the json data by using Google Chrome, and I can see the Content-Type of response is application/json in Chrome.
But when I used RestKit, I got this error about 'Expected status code in (400-499), got 200', I think 200 is fine, why the RestKit is expecting 400 - 499 rather than 200? And I can see the json object in the error message too. which is {"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}.
Thanks.
Upvotes: 4
Views: 2269
Reputation: 2591
When you define the response descriptor for a request, you need to set the status code to RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful) if you expect a response with http status code 2xx
Example:
[RKResponseDescriptor responseDescriptorWithMapping:yourMapping method:RKRequestMethodAny pathPattern:yourPattern keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
UPDATE:
Make sure that the pathPattern of the response descriptor matches the request path. Otherwise RestKit will use the error response descriptor (if you define it), and expect a response with a different status code.
Upvotes: 6