Skip to content

Commit e7a13b4

Browse files
committed
api add retry count
1 parent 15088c9 commit e7a13b4

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/HTTP/Base/VPUPHTTPBaseAPI.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ typedef NSURL* _Nonnull (^VPUPApiDownloadDestination)(NSURL * _Nonnull targetPat
7878
*/
7979
@property (nonatomic, assign, readonly) NSUInteger apiId;
8080

81+
/**
82+
* 用户api请求失败后重试的次数
83+
*/
84+
@property (nonatomic, assign, readonly) NSUInteger retryCount;
85+
86+
- (void)setRetryCount:(NSUInteger)retryCount;
87+
8188
/**
8289
* 用户api请求中的参数列表
8390
* 如果JSON-RPC协议,则Parameters 放入JSON-RPC协议中

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/HTTP/Base/VPUPHTTPBaseAPI.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@interface VPUPHTTPBaseAPI()
1616

1717
@property (nonatomic, assign) NSUInteger apiId;
18+
@property (nonatomic, assign) NSUInteger retryCount;
1819

1920
@end
2021

@@ -24,10 +25,15 @@ - (instancetype)init {
2425
self = [super init];
2526
if (self) {
2627
_apiId = [VPUPAutoNumberIDUtil getUniqueID];
28+
_retryCount = 0;
2729
}
2830
return self;
2931
}
3032

33+
- (void)setRetryCount:(NSUInteger)retryCount {
34+
_retryCount = retryCount;
35+
}
36+
3137
- (nullable NSURL *)requestURL {
3238
return nil;
3339
}

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Common/HTTP/VPUPHTTPManager.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ - (void)callAPICompletion:(VPUPHTTPBaseAPI *)api
462462
obj:(id)obj
463463
error:(NSError *)error
464464
task:(NSURLSessionTask *)task {
465+
466+
if (error && api.retryCount > 0) {
467+
[api setRetryCount:api.retryCount - 1];
468+
[self sendAPIRequest:api];
469+
return;
470+
}
471+
465472
obj = [api apiResponseObjReformer:obj andError:error];
466473
if ([api apiCompletionHandler]) {
467474
dispatch_queue_t callBackQueue = [api callbackQueue] ? : dispatch_get_main_queue();

VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/VideoPlsUtilsPlatformSDK/Subspec/HTTP/VPUPHTTPAFNManager.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ - (void)callAPICompletion:(VPUPHTTPBaseAPI *)api
334334
obj:(id)obj
335335
error:(NSError *)error
336336
task:(NSURLSessionTask *)task {
337+
338+
if (error && api.retryCount > 0) {
339+
[api setRetryCount:api.retryCount - 1];
340+
[self sendAPIRequest:api];
341+
return;
342+
}
343+
337344
obj = [api apiResponseObjReformer:obj andError:error];
338345
if ([api apiCompletionHandler]) {
339346
dispatch_queue_t callBackQueue = [api callbackQueue] ? : dispatch_get_main_queue();

0 commit comments

Comments
 (0)