Authored by chen.yanyan

NETWORK和IMAGELOAD类型错误需添加上报tec、cts字段 review by 呆死

... ... @@ -17,5 +17,6 @@
@property (copy, nonatomic) NSString *ts; // 时间戳
@property (copy, nonatomic) NSString *et; // 错误类型 error type (network / crash)
@property (copy, nonatomic) NSDictionary *param; // 操作参数
@property (copy, nonatomic) NSString *tec; //第三方网络错误码
@property (assign, nonatomic) NSTimeInterval cts; //第三方网络请求时间
@end
... ...
... ... @@ -27,6 +27,8 @@
JsonKeyErrorSID : self.sid ? self.sid : @"",
JsonKeyErrorET : self.et ? self.et : @"",
JsonKeyErrorPARAM : self.param ? self.param : @"",
JsonKeyErrorTEC : self.tec ? self.tec : @"",
JsonKeyErrorCTS : @(self.cts),
};
}
... ...
... ... @@ -26,4 +26,7 @@ typedef void (^YHNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus sta
+ (void)uploadFirstLaunchAppByGuangDiaTong:(NSDictionary *)parameters completionBlock:(void (^)(BOOL flag, NSError *error))block;
- (void)getbaiduNetStatus:(NSDictionary *)parameters completionBlock:(void (^)(NSTimeInterval cts, NSInteger errCode))block;
@end
... ...
... ... @@ -13,6 +13,7 @@
@property (strong, nonatomic) AFHTTPRequestOperationManager *httpClient;
@property (readwrite, nonatomic, copy) YHNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
@property (strong, nonatomic) AFHTTPRequestOperationManager *baiduManager;
@end
... ... @@ -37,6 +38,15 @@
self.httpClient.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
self.httpClient.securityPolicy.allowInvalidCertificates = YES;
self.httpClient.operationQueue.maxConcurrentOperationCount = 6;
self.baiduManager = [AFHTTPRequestOperationManager manager];
[self.baiduManager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
self.baiduManager.requestSerializer.timeoutInterval = 10.f;
[self.baiduManager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer];
responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/json", @"text/plain", @"text/html", @"text/xml", nil];
[self.baiduManager setResponseSerializer:responseSerializer];
}
return self;
}
... ... @@ -195,4 +205,25 @@
}
}
#pragma mark baidu
- (void)getbaiduNetStatus:(NSDictionary *)parameters completionBlock:(void (^)(NSTimeInterval cts, NSInteger errCode))block
{
NSDate *startDate = [NSDate date];
[self.baiduManager POST:kbaiduApiMethod parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDate *endDate = [NSDate date];
if (block) {
NSTimeInterval cts = [endDate timeIntervalSinceDate:startDate] * 1000.0;
block(cts,operation.response.statusCode);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%zd",operation.response.statusCode);
NSDate *endDate = [NSDate date];
if (block) {
NSTimeInterval cts = [endDate timeIntervalSinceDate:startDate] * 1000.0;
block(cts,error.code);
}
}];
}
@end
... ...
... ... @@ -50,6 +50,8 @@
#define kYASApiMethodGetNewStrategy @"" // 获取新发送策略,接口名未定
#define kbaiduApiMethod @"https://m.baidu.com" // baidu
#if defined TESTENV
#define YA_httpHost @"http://testapi.yoho.cn:28078"
//#define YA_httpHost @"http://test2.open.yohobuy.com"
... ... @@ -122,6 +124,9 @@
#define JsonKeyErrorMethod @"method" // httpMethod是GET or POST
#define JsonKeyErrorBody @"body" // POST请求的body
#define JsonKeyErrorResponse @"response" // 请求返回的数据
#define JsonKeyErrorTEC @"tec" // 第三方百度返回错误码
#define JsonKeyErrorCTS @"cts" // 第三方百度返回错误码时间
// Performance参数
#define JsonKeyPerformanceUID @"uid" // 用户id
... ...
... ... @@ -19,7 +19,7 @@
#import "YHError.h"
#import "YHEvent.h"
#import "YHPerformance.h"
//#import "YHNetworkService.h"
#import "YHNetworkService.h"
@interface YH_Analytics ()
... ... @@ -288,16 +288,36 @@
{
YALog(@"logError %@, %@", errorType, param);
if([errorType isEqualToString:kErrorTypeIMAGELOAD] ||[errorType isEqualToString:kErrorTypeHTTP]) {
[[YHNetworkService sharedInstance] getbaiduNetStatus:nil completionBlock:^(NSTimeInterval cts, NSInteger errCode) {
[self precessLogPara:errorType parameters:param cts:cts error:errCode];
}];
} else {
[self precessLogPara:errorType parameters:param cts:0.0 error:0];
}
}
- (void)precessLogPara:(NSString *)errorType parameters:(NSDictionary *)param cts:(NSTimeInterval)cts error:(NSInteger)errorCode
{
YHError *error = [[YHError alloc] init];
error.et = errorType;
error.uid = self.uid ? self.uid : @"";
error.ts = [self timestamp];
error.sid = self.session;
if([errorType isEqualToString:kErrorTypeIMAGELOAD] ||[errorType isEqualToString:kErrorTypeHTTP]) {
error.cts = cts;
if (cts >= 10000.0) {
error.tec = @"-1";
} else {
error.tec =[NSString stringWithFormat:@"%ld",(long)errorCode];
}
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:param];
[params setObject:self.cid?:@"" forKey:JsonKeyEventCID];
error.param = params;
// crash 不支持立即发送
if ((self.logStrategy & LogStrategyImmedi) != 0 && ![errorType isEqualToString:kErrorTypeCrash]) {
[[YHAssemblyAssistant sharedInstance] uploadImmedilyWithEvent:error];
... ...