同事在收到 502 错误时, sdk 跑蹦, 因此调源码:
参考源码:
https://github.com/qiniu/objc-sdk
源码修改:
QNResponseInfo.m 文件: 在 init 函数里 NSDictionary *uInfo 有可能是 nil 502错误没有json格式数据
- (instancetype)init:(int)status
withReqId:(NSString *)reqId
withXLog:(NSString *)xlog
withBody:(NSData *)body {
if (self = [super init]) {
_statusCode = status;
_reqId = [reqId copy];
_xlog = [xlog copy];
if (status != 200) {
if (body == nil) {
_error = [[NSError alloc] initWithDomain:domain code:_statusCode userInfo:nil];
} else {
NSError *tmp;
NSDictionary *uInfo = [NSJSONSerialization JSONObjectWithData:body options:NSJSONReadingMutableLeaves error:&tmp];
/* 这段需要做 uInfo nil 判断, 否则代码执行会蹦 */
if (tmp != nil && uInfo != nil) {
uInfo = @{ @"error":[[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding] };
}
_error = [[NSError alloc] initWithDomain:domain code:_statusCode userInfo:uInfo];
}
}
else if (body == nil || body.length == 0) {
NSDictionary *uInfo = @{ @"error":@"no response json" };
_error = [[NSError alloc] initWithDomain:domain code:_statusCode userInfo:uInfo];
}
}
return self;
}
非常感谢你的建议,我们本地还原下场景,能否告知下info中间返回502有什么具体的报错信息,代码修改的问题你可以直接在 https://github.com/qiniu/objc-sdk/issues 中新建issue进行反馈。