Skip to content

Commit 2f18c38

Browse files
committed
fixed non utf8 body
1 parent 74c338f commit 2f18c38

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ - (instancetype)init:(int)status
9393
NSError *tmp;
9494
NSDictionary *uInfo = [NSJSONSerialization JSONObjectWithData:body options:NSJSONReadingMutableLeaves error:&tmp];
9595
if (tmp != nil) {
96-
uInfo = @{ @"error":[[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding] };
96+
// 出现错误时,如果信息是非UTF8编码会失败,返回nil
97+
NSString *str = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding];
98+
if (str == nil) {
99+
str = @"";
100+
}
101+
uInfo = @{ @"error": str };
97102
}
98103
_error = [[NSError alloc] initWithDomain:domain code:_statusCode userInfo:uInfo];
99104
}

0 commit comments

Comments
 (0)