Added new type of DataCenterMigrateException - NetworkMigrateException

Now we catch not only PhoneMigrateException but all DataCenterMigrationExceptions and reconnect
Fixes #568
This commit is contained in:
Daniel Vygolov 2017-09-23 16:06:54 +04:00 committed by Andres G. Aragoneses
parent 133b9fdf6c
commit 0015cf494b
2 changed files with 16 additions and 2 deletions

View file

@ -305,6 +305,12 @@ namespace TLSharp.Core.Network
var dcIdx = int.Parse(resultString); var dcIdx = int.Parse(resultString);
throw new UserMigrationException(dcIdx); throw new UserMigrationException(dcIdx);
} }
else if (errorMessage.StartsWith("NETWORK_MIGRATE_"))
{
var resultString = Regex.Match(errorMessage, @"\d+").Value;
var dcIdx = int.Parse(resultString);
throw new NetworkMigrationException(dcIdx);
}
else if (errorMessage == "PHONE_CODE_INVALID") else if (errorMessage == "PHONE_CODE_INVALID")
{ {
throw new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram"); throw new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
@ -571,4 +577,12 @@ namespace TLSharp.Core.Network
{ {
} }
} }
internal class NetworkMigrationException : DataCenterMigrationException
{
internal NetworkMigrationException(int dc)
: base($"Network located on a different DC: {dc}.", dc)
{
}
}
} }

View file

@ -145,7 +145,7 @@ namespace TLSharp.Core
completed = true; completed = true;
} }
catch (PhoneMigrationException ex) catch (DataCenterMigrationException ex)
{ {
await ReconnectToDcAsync(ex.DC); await ReconnectToDcAsync(ex.DC);
} }