diff --git a/YTKNetwork/YTKBaseRequest.h b/YTKNetwork/YTKBaseRequest.h index c79fc59..0f405fc 100644 --- a/YTKNetwork/YTKBaseRequest.h +++ b/YTKNetwork/YTKBaseRequest.h @@ -332,6 +332,9 @@ typedef void(^YTKRequestCompletionBlock)(__kindof YTKBaseRequest *request); /// This validator will be used to test if `responseStatusCode` is valid. - (BOOL)statusCodeValidator; +/// Use this to custom validate with specific error. +- (BOOL)customValidatorWithError:(NSError * _Nullable __autoreleasing *)error; + @end NS_ASSUME_NONNULL_END diff --git a/YTKNetwork/YTKBaseRequest.m b/YTKNetwork/YTKBaseRequest.m index 828b01f..aaa8fc7 100644 --- a/YTKNetwork/YTKBaseRequest.m +++ b/YTKNetwork/YTKBaseRequest.m @@ -202,6 +202,10 @@ - (BOOL)statusCodeValidator { return (statusCode >= 200 && statusCode <= 299); } +- (BOOL)customValidatorWithError:(NSError * _Nullable __autoreleasing *)error { + return YES; +} + #pragma mark - NSObject - (NSString *)description { diff --git a/YTKNetwork/YTKNetworkAgent.m b/YTKNetwork/YTKNetworkAgent.m index dbe24ac..d9ed6cb 100644 --- a/YTKNetwork/YTKNetworkAgent.m +++ b/YTKNetwork/YTKNetworkAgent.m @@ -271,6 +271,12 @@ - (BOOL)validateResult:(YTKBaseRequest *)request error:(NSError * _Nullable __au } return result; } + + result = [request customValidatorWithError:error]; + if (!result) { + return result; + } + id json = [request responseJSONObject]; id validator = [request jsonValidator]; if (json && validator) {