-(void)outError:(NSError*)errorandUrlStr:(NSString*)urlStr{
// NSString *domain = error.domain;
//服务器报错信息
NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
//服务器报错响应头
NSHTTPURLResponse*reoponseData = error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey];
//其他错误 404或者其它
if(!errorData ||!reoponseData) {
[MBProgressHUDshowError:@"网络错误"];
return;
}
//格式化服务器报错信息
NSDictionary*serializedData = [NSJSONSerializationJSONObjectWithData: errorDataoptions:kNilOptionserror:nil];
if([serializedDataisKindOfClass:[NSDictionaryclass]]&&[reoponseDataisKindOfClass:[NSHTTPURLResponseclass]]) {
NSString*data = [serializedDataobjectForKey:@"data"];
NSString*errStr = [NSStringstringWithFormat:@"---请求失败----\nurlString:%@ \n code:%ld \nInfo:%@",urlStr,reoponseData.statusCode,data];
// NSLog(@"---请求失败--- domain:%@----code:%ld ---Info:%@", domain ,reoponseData.statusCode,data);
[MBProgressHUDshowError:errStr];
}
else{
[MBProgressHUDshowError:@"其他错误"];
}
}