Skip to content

Commit

Permalink
MOD: refactor YTKNetworkAgent, expose more errors
Browse files Browse the repository at this point in the history
Change-Id: I447f354eefa1175e9801ab7352927510b17b32a6
  • Loading branch information
liujl committed Sep 13, 2016
1 parent 6ae6563 commit f210739
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 189 deletions.
24 changes: 20 additions & 4 deletions YTKNetwork/YTKBaseRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@

NS_ASSUME_NONNULL_BEGIN

FOUNDATION_EXPORT NSString *const YTKRequestValidationErrorDomain;

NS_ENUM(NSInteger) {
YTKRequestValidationErrorInvalidStatusCode = -8,
YTKRequestValidationErrorInvalidJSONFormat = -9,
};

/// HTTP Request method.
typedef NS_ENUM(NSInteger, YTKRequestMethod) {
YTKRequestMethodGET = 0,
Expand Down Expand Up @@ -261,15 +268,24 @@ typedef void(^YTKRequestCompletionBlock)(__kindof YTKBaseRequest *request);
/// Called on the main thread when request failed.
- (void)requestFailedFilter;

/// The URL of request.
/// The baseURL of request. This should only contain the host part of URL, e.g., http://www.example.com.
/// See also `requestUrl`
- (NSString *)baseUrl;

/// The URL path of request. This should only contain the path part of URL, e.g., /v1/user. See alse `baseUrl`.
///
/// @discussion This will be concated with `baseUrl` using [NSURL URLWithString:relativeToURL].
/// Because of this, it is recommended that the usage should stick to rules stated above.
/// Otherwise the result URL may not be correctly formed. See also `URLString:relativeToURL`
/// for more information.
///
/// Additionaly, if `requestUrl` itself is a valid URL, it will be used as the result URL and
/// `baseUrl` will be ignored.
- (NSString *)requestUrl;

/// Optional CDN URL for request.
- (NSString *)cdnUrl;

/// The baseURL of request.
- (NSString *)baseUrl;

/// Requset timeout interval. Default is 60s.
///
/// @discussion When using `resumableDownloadPath`(NSURLSessionDownloadTask), the session seems to completely ignore
Expand Down
2 changes: 2 additions & 0 deletions YTKNetwork/YTKBaseRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#import "AFNetworking.h"
#endif

NSString *const YTKRequestValidationErrorDomain = @"com.yuantiku.request.validation";

@interface YTKBaseRequest ()

@property (nonatomic, strong, readwrite) NSURLSessionTask *requestTask;
Expand Down
Loading

0 comments on commit f210739

Please sign in to comment.