Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新版本的代码逻辑不通 #23

Open
datoujiejie opened this issue Jan 10, 2019 · 1 comment
Open

最新版本的代码逻辑不通 #23

datoujiejie opened this issue Jan 10, 2019 · 1 comment

Comments

@datoujiejie
Copy link

CTApiProxy中
NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:&error];
如果上面返回的error是nil,对error取地址的话是有值的
接下来Demoservice中,提前返回了,造成请求成功时kCTApiProxyValidateResultKeyResponseObject里面的值为空,后面的请求结果拿不到值

`- (NSDictionary *)resultWithResponseObject:(id)responseObject response:(NSURLResponse *)response request:(NSURLRequest *)request error:(NSError **)error
{
NSMutableDictionary *result = [[NSMutableDictionary alloc] init];
if (error || !responseObject) {
return result;
}

if ([responseObject isKindOfClass:[NSData class]]) {
    result[kCTApiProxyValidateResultKeyResponseString] = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
    result[kCTApiProxyValidateResultKeyResponseObject] = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:NULL];
} else {
    //这里的kCTApiProxyValidateResultKeyResponseString是用作打印日志用的,实际使用时可以把实际类型的对象转换成string用于日志打印

// result[kCTApiProxyValidateResultKeyResponseString] = responseObject;
result[kCTApiProxyValidateResultKeyResponseObject] = responseObject;
}

return result;

}`

既然error是用于判断的,就不要写成 error:(NSError **)error这种形式,建议修改如下

NSDictionary *result = [request.service resultWithResponseObject:responseObject response:response request:request error:error];
- (NSDictionary *)resultWithResponseObject:(id)responseObject response:(NSURLResponse *)response request:(NSURLRequest *)request error:(NSError *)error

@WeihaoChenHb
Copy link

这个地方的逻辑有问题,要么直接传入error,然后用error做判断
如果要传入&error,那么做判断的时候用*error来做判断

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants