Authored by ZhangTonghai

大数据上报错误信息上报南京

... ... @@ -7,7 +7,7 @@
//
#import "YHNetworkService.h"
#import "YH_Analytics.h"
@interface YHNetworkService ()
... ... @@ -74,7 +74,7 @@
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:actualParameters options:0 error:&error];
if (error) {
YALog(@"json parsing, connot convert to json for: %@\n code: %ld\n reason: %@", actualParameters, (long)[error code], [error localizedDescription]);
YALog(@"json parsing, connot convert to json for: %@\n code: %zd\n reason: %@", actualParameters, [error code], [error localizedDescription]);
if (block) {
block(NO, error);
... ... @@ -90,13 +90,91 @@
if (block) {
block(YES, nil);
}
[self reportUploadError:operation withResponse:responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (block) {
block(NO, error);
}
[self reportUplaodError:operation withError:error];
}];
}
- (void)reportUploadError:(AFHTTPRequestOperation *)operation withResponse:(id)responseObject
{
#ifdef APPYOHO
if (operation.response.statusCode == 200) {
return;
}
NSInteger code = [[responseObject objectForKey:@"code"] integerValue];
NSString *url = operation.request.URL.absoluteString;
NSString *method = [operation.request.HTTPMethod uppercaseString];
NSString *body = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding];
id response = nil;
if (IsDictionaryClass(responseObject)) {
response = responseObject;
} else {
response = [responseObject description];
}
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
//超时返回是0,但是为了和android的统一性,ios修改成-1。
if (code == 0) {
parameters[JsonKeyErrorEC] = @(-1);
} else {
parameters[JsonKeyErrorEC] = @(code);
}
if (!IsStrEmpty(url)) {
parameters[JsonKeyErrorEI] = url;
}
if (!IsStrEmpty(method)) {
parameters[JsonKeyErrorMethod] = method;
}
if (!IsStrEmpty(body)) {
parameters[JsonKeyErrorBody] = body;
}
if (!IsNilOrNull(response)) {
parameters[JsonKeyErrorResponse] = response;
}
[[YH_Analytics sharedInstance] logError:kErrorTypeREPORT parameters:parameters];
#endif
}
- (void)reportUplaodError:(AFHTTPRequestOperation *)operation withError:(NSError *)error
{
#ifdef APPYOHO
if (!error) {
return;
}
NSString *url = operation.request.URL.absoluteString;
NSString *method = [operation.request.HTTPMethod uppercaseString];
NSString *body = [[NSString alloc] initWithData:operation.request.HTTPBody encoding:NSUTF8StringEncoding];
NSString *response = (*error).localizedDescription;
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
//超时返回是0,但是为了和android的统一性,ios修改成-1。
if (operation.response.statusCode == 0) {
parameters[JsonKeyErrorEC] = @(-1);
} else {
parameters[JsonKeyErrorEC] = @(operation.response.statusCode);
}
if (!IsStrEmpty(url)) {
parameters[JsonKeyErrorEI] = url;
}
if (!IsStrEmpty(method)) {
parameters[JsonKeyErrorMethod] = method;
}
if (!IsStrEmpty(body)) {
parameters[JsonKeyErrorBody] = body;
}
if (!IsStrEmpty(response)) {
parameters[JsonKeyErrorResponse] = response;
}
[[YH_Analytics sharedInstance] logError:kErrorTypeREPORT parameters:parameters];
#endif
}
- (AFHTTPRequestOperation *)uploadLogcustomURL:(NSString *)url parameters:(NSDictionary *)parameters completionBlock:(void (^)(BOOL success, NSError *error))block
{
NSError *error = nil;
... ...
... ... @@ -173,6 +173,7 @@
#define kErrorTypeHTTP @"NETWORK" // HTTP返回非200的网络错误(et为NETWORK)
#define kErrorTypePoc @"PoC" // 业务返回非200的业务错误(et为PoC)
#define kErrorTypeIMAGELOAD @"IMAGELOAD"// 图片加载错误(et为IMAGELOAD)
#define kErrorTypeREPORT @"REPORT"// 大数据上报错误(et为REPORT)
// Performance信息类型
#define kPerformanceTypeImageLoad @"IMG_LOAD"
... ...
... ... @@ -86,6 +86,11 @@ typedef NS_ENUM(NSInteger, YHLogStrategy) {
@property (assign, nonatomic, readonly) YHLogStrategy logStrategy;
/**
* 操作序数
*/
@property (assign, nonatomic) NSUInteger eventIndex;
/**
* 间隔发送策略下,间隔时间
*/
@property (assign, nonatomic, readonly) NSTimeInterval currentInterval;
... ...
... ... @@ -35,7 +35,7 @@
/**
* 操作序数
*/
@property (assign, nonatomic) NSUInteger eventIndex;
//@property (assign, nonatomic) NSUInteger eventIndex;
/**
* 发送策略
*/
... ...