Add some additional log messages to track down a tvdb issue.

This commit is contained in:
Damiano Galassi committed 2017-05-31 09:38:46 +02:00
1 parent 7721818507
commit 3d285f692f
5 files changed
+51 -14

No files matched your search

@@ -7,6 +7,7 @@
//
#import <Foundation/Foundation.h>
#import <MP42Foundation/MP42Logging.h>
NS_ASSUME_NONNULL_BEGIN
@@ -22,6 +23,8 @@ typedef NS_ENUM(NSUInteger, SBCachePolicy) {
+ (nullable NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename;
+ (NSString *)urlEncoded:(NSString *)string;
@property (class) id<MP42Logging> logger;
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url cachePolicy:(SBCachePolicy)policy;
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(SBCachePolicy)policy;
+ (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(NSURLRequestCachePolicy)cachePolicy completionHandler:(void(^)(NSData * _Nullable data))completionHandler;
@@ -9,8 +9,20 @@
#import "SBMetadataHelper.h"
#import <CommonCrypto/CommonDigest.h>
static id<MP42Logging> _logger;
@implementation SBMetadataHelper
+ (void)setLogger:(id<MP42Logging>)logger
{
_logger = logger;
}
+ (id<MP42Logging>)logger
{
return _logger;
}
+ (nullable NSDictionary<NSString *, NSString *> *)parseFilename:(NSString *)filename
{
NSParameterAssert(filename);
@@ -195,8 +207,11 @@
request.HTTPBody = body;
}
[_logger writeToLog:[NSString stringWithFormat:@"Requesting URL %@", url.absoluteString]];
NSURLSession *defaultSession = [NSURLSession sharedSession];
NSURLSessionTask *task = [defaultSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {
NSUInteger statusCode = 0;
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
@@ -207,9 +222,17 @@
completionHandler(data);
}
else {
NSString *errorData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (errorData) {
[_logger writeToLog:errorData];
}
completionHandler(nil);
}
}
if (error) {
[_logger writeErrorToLog:error];
}
}];
return task;