添加了接口报错的上报

This commit is contained in:
fengshuo
2022-10-31 14:33:35 +08:00
parent 6c1b86763a
commit 036e5a9352

View File

@@ -11,6 +11,7 @@
#import "AccountInfoStorage.h" #import "AccountInfoStorage.h"
#import "YYReachability.h" #import "YYReachability.h"
#import <AFNetworking.h> #import <AFNetworking.h>
#import <Bugly/Bugly.h>
@implementation HttpRequestHelper @implementation HttpRequestHelper
@@ -60,7 +61,7 @@
#endif #endif
success(baseModel); success(baseModel);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self handleNetError:error failure:failure]; [self handleNetError:error method:method failure:failure];
}]; }];
} }
@@ -90,7 +91,7 @@
#endif #endif
success(baseModel); success(baseModel);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self handleNetError:error failure:failure]; [self handleNetError:error method:method failure:failure];
}]; }];
} }
@@ -102,6 +103,8 @@
if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) { if ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
failure(-1, @"请检查网络连接。"); failure(-1, @"请检查网络连接。");
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
}); });
return; return;
} }
@@ -119,8 +122,10 @@
NSLog(@"\n%@", [baseModel toJSONString]); NSLog(@"\n%@", [baseModel toJSONString]);
#endif #endif
success(baseModel); success(baseModel);
NSException * extrion= [NSException exceptionWithName:method reason:@"接口没有网络" userInfo:nil];
[Bugly reportException:extrion];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[self handleNetError:error failure:failure]; [self handleNetError:error method:method failure:failure];
}]; }];
} }
@@ -201,7 +206,7 @@
return dic; return dic;
} }
+ (void)handleNetError:(NSError *)error + (void)handleNetError:(NSError *)error method:(NSString *)method
failure:(void (^)(NSInteger resCode, NSString *message))failure failure:(void (^)(NSInteger resCode, NSString *message))failure
{ {
#ifdef DEBUG #ifdef DEBUG
@@ -217,6 +222,12 @@
} else { } else {
failure(error.code, @"服务器正忙,请稍后重试。"); failure(error.code, @"服务器正忙,请稍后重试。");
} }
NSString * code = error.code ? [NSString stringWithFormat:@"%ld", error.code] : @"9999";
NSString * des = error.description.length > 0 ? error.description : @"接口报错信息未知";
NSException *exception = [NSException exceptionWithName:@"229181"
reason:method
userInfo:@{@"code":code, @"desc":des}];
[Bugly reportException:exception];
} }
} }
@@ -296,7 +307,7 @@
} }
} }
if (error) { if (error) {
[self handleNetError:error failure:^(NSInteger resCode, NSString *message) { [self handleNetError:error method:path failure:^(NSInteger resCode, NSString *message) {
completion(nil, resCode, message); completion(nil, resCode, message);
}]; }];
} }