Skip to content

Commit

Permalink
only trigger logging when options.debug is true
Browse files Browse the repository at this point in the history
  • Loading branch information
gliechtenstein committed Aug 19, 2017
1 parent bbd0d1a commit 4948dc6
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions app/Jasonette/JasonNetworkAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,18 @@ - (void)request{
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
}

[self log:@{
@"type": @"request",
@"options": @{
@"method": method,
@"url": url,
@"header": manager.requestSerializer.HTTPRequestHeaders,
@"body": (parameters ? parameters : @{})
}
}];

if(self.options[@"debug"]) {
[self log:@{
@"type": @"request",
@"options": @{
@"method": method,
@"url": url,
@"header": manager.requestSerializer.HTTPRequestHeaders,
@"body": (parameters ? parameters : @{})
}
}];
}

if(method){
if([[method lowercaseString] isEqualToString:@"post"]){
Expand All @@ -171,13 +174,14 @@ - (void)request{
[manager POST:url parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
// Nothing
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];

if(self.options[@"debug"]) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];
}
// Ignore if the url is different
if(![JasonHelper isURL:task.originalRequest.URL equivalentTo:url]) return;
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -203,13 +207,14 @@ - (void)request{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[manager.operationQueue cancelAllOperations];
[manager PUT:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];

if(self.options[@"debug"]) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];
}
// Ignore if the url is different
if(![JasonHelper isURL:task.originalRequest.URL equivalentTo:url]) return;
dispatch_async(dispatch_get_main_queue(), ^{
Expand All @@ -236,13 +241,14 @@ - (void)request{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
[manager.operationQueue cancelAllOperations];
[manager DELETE:url parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];

if(self.options[@"debug"]) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];
}
// Ignore if the url is different
if(![JasonHelper isURL:task.originalRequest.URL equivalentTo:url]) return;
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down Expand Up @@ -277,13 +283,14 @@ - (void)request{
[manager GET:url parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
// Nothing
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];

if(self.options[@"debug"]) {
[self log:@{
@"type": @"response",
@"options": @{
@"method": method, @"url": url, @"dataType": (dataType ? dataType : @"json"), @"responseObject": responseObject
}
}];
}
// Ignore if the url is different
if(![JasonHelper isURL:task.originalRequest.URL equivalentTo:url]) return;
dispatch_async(dispatch_get_main_queue(), ^{
Expand Down

0 comments on commit 4948dc6

Please sign in to comment.