(fix):When a ephemeral session configuration causes an exception, catch try background or return nil. #417
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…of test for this.
Summary
This wraps the ephemeral session creation with a try catch and logs an error. if it fails, it returns nil which will in turn cause the session to be nil which will in turn make the NSURLSessionUploadTask nil in which case resume will be a noop and the completion handler would never be called. This should result in a failed session being a noop.
Test plan
Here is where the magic of objective-c happens. I wrote a unit test by swizzling URLSessionConfiguration to raise an exception. I then swizzle it back after the test completes.
I discovered with this test that attempting to use a background session can cause a different kind of exception. So, in order to avoid any such exception, we simply return nil and the event is not sent. It will then be sent on the next attempt to send events.