...
|
...
|
@@ -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;
|
...
|
...
|
|