TelegramClient: move the _sender null check to RequestWithDcMigration()

The method IsPhoneRegisteredAsync() was calling
RequestWithDcMigration() which was the real method
that made use of the _sender field, so we can move
the null check to there.

This will also help track down possible NullReferenceExceptions
that could happen when other callers of this method
arrive with a bad _sender, which might aid us trying
to fix #706.
This commit is contained in:
Andres G. Aragoneses 2018-02-28 08:43:28 +08:00
parent fe2baf5110
commit 4ce0f72d6d

View file

@ -111,6 +111,9 @@ namespace TLSharp.Core
private async Task RequestWithDcMigration(TLMethod request)
{
if (_sender == null)
throw new InvalidOperationException("Not connected!");
var completed = false;
while(!completed)
{
@ -139,9 +142,6 @@ namespace TLSharp.Core
if (String.IsNullOrWhiteSpace(phoneNumber))
throw new ArgumentNullException(nameof(phoneNumber));
if (_sender == null)
throw new InvalidOperationException("Not connected!");
var authCheckPhoneRequest = new TLRequestCheckPhone() { PhoneNumber = phoneNumber };
await RequestWithDcMigration(authCheckPhoneRequest);