我使用的是RestKit v0.24.1
这是我的请求失败的响应主体:
response.body={"status":400,"code":2007,"message":"Account password minimum length not satisfied.","developerMessage":"Account password minimum length not satisfied.","moreInfo":"http://docs.stormpath.com/errors/2007"}
2015-04-08 12:15:46.405 [20034:540848] D restkit.object_mapping:RKMapperOperation.m:407 Executing mapping operation for representation: {
code = 2007;
developerMessage = "Account password minimum length not satisfied.";
message = "Account password minimum length not satisfied.";
moreInfo = "http://docs.stormpath.com/errors/2007";
status = 400;
}
这是我的要求:
RKObjectManager.sharedManager().postObject(account, path:STORMPATH_URL_ACCOUNTS, parameters: nil, success: {(operation: RKObjectRequestOperation!, result) in
NSLog("New account created")
onSuccess?()
}, failure: {(operation: RKObjectRequestOperation!, error: NSError!) in
NSLog("New account NOT created")
var userInfo = error.userInfo! as NSDictionary
var errors = userInfo.objectForKey(RKObjectMapperErrorObjectsKey) as NSArray
var lError = errors.lastObject as LError
println("Message: \(lError.message)")
}
)
这是我的错误"我要映射的课程:
import Foundation
@objc(LError)
class LError: NSObject
{
var status: NSNumber!
var code: NSNumber!
var message: String!
var developerMessage: String!
}
这是我的描述符代码:
//Error mapping
var errorMapping = RKObjectMapping(forClass: LError.self)
errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: "status", toKeyPath: "status"))
errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: "code", toKeyPath: "code"))
errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: "message", toKeyPath: "message"))
errorMapping.addPropertyMapping(RKAttributeMapping(fromKeyPath: "developerMessage", toKeyPath: "developerMessage"))
var errorDescriptor = RKResponseDescriptor(mapping: errorMapping, pathPattern: nil, keyPath: nil, statusCodes: RKStatusCodeIndexSetForClass(RKStatusCodeClass.ClientError))
responseDescriptors.addObject(errorDescriptor)
以下是RestKit在尝试绘制响应时对我大吼大叫的问题:
(400 Bad Request / 0 objects) [request=0.5180s mapping=0.0000s total=0.5246s]:
error=Error Domain=org.restkit.RestKit.ErrorDomain Code=1001 "No mappable object representations were found at the key paths searched." UserInfo=0x7a8329b0 {DetailedErrors=(
), NSLocalizedFailureReason=The mapping operation was unable to find any nested object representations at the key paths searched:
The representation inputted to the mapper was found to contain nested object representations at the following key paths: code, developerMessage, message, moreInfo, status
This likely indicates that you have misconfigured the key paths for your mappings., NSLocalizedDescription=No mappable object representations were found at the key paths searched., keyPath=null}
我做错了什么?