4

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.

Jake Lin
  • 11,146
  • 6
  • 29
  • 40
  • Show your mappings and response descriptor. Status code is set there so something doesn't line up. – Wain Jul 15 '13 at 21:49
  • 1
    @Wain thanks, I found out that's a mapping issue. please have a look at https://github.com/RestKit/RestKit/issues/1501 – Jake Lin Jul 17 '13 at 00:44

1 Answers1

6

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.

andreacipriani
  • 2,519
  • 26
  • 23