修复了异常的toast

This commit is contained in:
fengshuo
2022-11-10 12:11:25 +08:00
parent ef51ef81fa
commit 4f3c21152f
2 changed files with 9 additions and 5 deletions

View File

@@ -21,7 +21,6 @@
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager = [[AFHTTPSessionManager manager]initWithBaseURL:[NSURL URLWithString:API_HOST_URL]];
manager.requestSerializer.timeoutInterval = 15;
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer.HTTPShouldHandleCookies = YES;
//
@@ -31,6 +30,7 @@
//
[manager.securityPolicy setValidatesDomainName:NO];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain",@"image/jpeg",@"image/png", nil];
manager.requestSerializer.timeoutInterval = 40;
});
return manager;
}
@@ -43,6 +43,8 @@
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
});
return;
}
@@ -73,6 +75,8 @@
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
});
return;
}
@@ -122,8 +126,6 @@
NSLog(@"\n%@", [baseModel toJSONString]);
#endif
success(baseModel);
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self handleNetError:error method:method failure:failure];
}];
@@ -219,7 +221,9 @@
} else {
if (error.code == -1009) {
failure(error.code, @"网络异常,请检查网络后重试。");
} else {
} else if (error.code == -1001) {
failure(error.code, @"请求超时,请稍后再试。");
} else {
failure(error.code, @"服务器正忙,请稍后重试。");
}
NSString * code = error.code ? [NSString stringWithFormat:@"%ld", error.code] : @"9999";