Cannot process successful response 204 and correct card response using RestKit

I am writing an iOS application that interacts with a service to update a user profile. To update the username, the iOS application issues a request with the body in the following format:

 {"name" : {"first" : "FIRSTNAMEGOESHERE", "lastName":"LASTNAMEGOESHERE"}}

In the case when the request body is valid (that is, both the first and the last name are provided), the service returns a status code 204 (without content) and an empty response body.

If the request body is invalid (for example, the name is missing, etc.), the service will return a status code of 400 and the response body in the following format:

{"code":"ERRORCODEHERE"}

The iOS application uses RestKit, and I could not figure out how to get it to properly handle success as well as failure. If I use this:

- (void)updateUserName
{
    RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[[NSURL alloc] initWithString:@"http://someqaserver:8080"]];
    [objectManager setRequestSerializationMIMEType:RKMIMETypeJSON];

    RKObjectMapping *userMapping = [RKObjectMapping requestMapping];
    [userMapping addAttributeMappingsFromDictionary:@{@"firstName" : @"first", @"lastName" : @"last"}];

    RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:userMapping objectClass:[OurUser class]                                       rootKeyPath:@"name"];

    [objectManager addRequestDescriptor:requestDescriptor];

    [objectManager putObject:[OurUser getCurrentUser]
                   path:@"/mobile/profile/name"
                   parameters:nil
                   success:^(RKObjectRequestOperation *operation, RKMappingResult *result)
                   {
                     NSLog(@"Success!");
                   }
                   failure:^(RKObjectRequestOperation *operation, NSError *error)
                   {
                     NSLog(@"Fail!");
                   }];
}

, , 204 .

putObject, , 204- :

    RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[ServiceError class]];
    [errorMapping addAttributeMappingsFromDictionary:@{@"code" : @"errorCode"}];
    RKResponseDescriptor *errorDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassClientError)];
    [objectManager addResponseDescriptor:errorDescriptor];

, HTTP , , 204 (, , - ?)

, : 1.) 204, 2.) 4XX, ServiceError?

, .

+5
2

204:

RKResponseDescriptor *successResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[RKObjectMapping mappingForClass:nil]
                                                                                               method:RKRequestMethodPUT
                                                                                          pathPattern:nil
                                                                                              keyPath:nil
                                                                                          statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:successResponseDescriptor];
+2

204 , 2xx . 204 " ", . , restkit , , 3xx, 4xx 5xx. RKStatusCodeClassClientErrorm, , 4xx.

. wikipedia

0

All Articles