1
This commit is contained in:
@@ -4,9 +4,33 @@
|
||||
//
|
||||
|
||||
#import "KBMaiPointReporter.h"
|
||||
#import "KBLog.h"
|
||||
|
||||
NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
||||
|
||||
#if DEBUG
|
||||
static void KBMaiPoint_DebugLogURL(NSURLRequest *request) {
|
||||
NSString *url = request.URL.absoluteString ?: @"";
|
||||
KBLOG(@"🍃[KBMaiPointReporter] url=%@", url);
|
||||
}
|
||||
|
||||
static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) {
|
||||
if (error) {
|
||||
NSString *msg = error.localizedDescription ?: @"(no description)";
|
||||
KBLOG(@"🍃[KBMaiPointReporter] error=%@ domain=%@ code=%ld", msg, error.domain ?: @"", (long)error.code);
|
||||
return;
|
||||
}
|
||||
if ([response isKindOfClass:NSHTTPURLResponse.class]) {
|
||||
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode;
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
KBLOG(@"🍃[KBMaiPointReporter] status=HTTP_%ld", (long)statusCode);
|
||||
} else {
|
||||
KBLOG(@"🍃[KBMaiPointReporter] error=HTTP_%ld", (long)statusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@implementation KBMaiPointReporter
|
||||
|
||||
+ (instancetype)sharedReporter {
|
||||
@@ -89,6 +113,10 @@ NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
request.HTTPBody = body;
|
||||
|
||||
#if DEBUG
|
||||
KBMaiPoint_DebugLogURL(request);
|
||||
#endif
|
||||
|
||||
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||
config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
|
||||
@@ -115,6 +143,10 @@ NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
KBMaiPoint_DebugLogError(response, finalError);
|
||||
#endif
|
||||
|
||||
if (completion) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion(success, finalError);
|
||||
|
||||
Reference in New Issue
Block a user