Skip to content

Commit

Permalink
Add more info in error via NSRecoverySuggestionErrorKey
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed Feb 19, 2020
1 parent afd4853 commit 68f19da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ - (void) testVideo3ReturnsSomePlayableStreams
//I noticed when the file stored on the server is not complete we get this error
XCTAssertTrue([streamErrors.allValues.firstObject.domain isEqual:NSURLErrorDomain]);
XCTAssertEqual(streamErrors.allValues.firstObject.code, NSURLErrorNetworkConnectionLost);
XCTAssertNotNil(streamErrors.allValues.firstObject.userInfo[NSLocalizedRecoverySuggestionErrorKey]);
XCTAssertTrue([streamErrors.allValues.firstObject.userInfo[NSLocalizedRecoverySuggestionErrorKey] isEqual:@"The file stored on the server might be incomplete."]);
[expectation fulfill];
}];
}];
Expand Down
7 changes: 7 additions & 0 deletions XCDYouTubeKit/XCDURLGETOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ - (void) cancel
- (void)finishWithError:(NSError *)error
{
self.error = error;
if (error.code == NSURLErrorNetworkConnectionLost && [error.domain isEqual: NSURLErrorDomain])
{
//This might have failed because the file on YouTube's servers is incomplete. See https://github.com/0xced/XCDYouTubeKit/issues/456 for more info.
NSMutableDictionary *modifiedUserInfo = self.error.userInfo.mutableCopy;
modifiedUserInfo[NSLocalizedRecoverySuggestionErrorKey] = @"The file stored on the server might be incomplete.";
self.error = [NSError errorWithDomain:(NSString *)self.error.domain code:self.error.code userInfo:modifiedUserInfo.copy];
}
XCDYouTubeLogError(@"URL GET operation finished with error: %@\nDomain: %@\nCode: %@\nUser Info: %@", self.error.localizedDescription, self.error.domain, @(self.error.code), self.error.userInfo);
[self finish];
}
Expand Down

0 comments on commit 68f19da

Please sign in to comment.